active_record-events 1.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,14 @@
1
1
  class Task < ActiveRecord::Base
2
2
  has_event :complete
3
+ has_events :archive, skip_scopes: true
4
+
5
+ def complete!
6
+ super
7
+ logger.info("Task #{id} has been completed")
8
+ end
9
+
10
+ def self.complete_all
11
+ super
12
+ logger.info('All tasks have been completed')
13
+ end
3
14
  end
@@ -1,5 +1,6 @@
1
- # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
1
+ ENV['RAILS_ENV'] ||= 'development'
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
3
3
 
4
4
  require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
5
+
6
+ $LOAD_PATH.unshift(File.expand_path('../../../lib', __dir__))
@@ -5,7 +5,7 @@
5
5
  # gem 'sqlite3'
6
6
  development:
7
7
  adapter: sqlite3
8
- database: spec/dummy/db/development.sqlite3
8
+ database: db/development.sqlite3
9
9
  pool: 5
10
10
  timeout: 5000
11
11
 
@@ -14,12 +14,12 @@ development:
14
14
  # Do not set this db to the same as development or production.
15
15
  test:
16
16
  adapter: sqlite3
17
- database: spec/dummy/db/test.sqlite3
17
+ database: db/test.sqlite3
18
18
  pool: 5
19
19
  timeout: 5000
20
20
 
21
21
  production:
22
22
  adapter: sqlite3
23
- database: spec/dummy/db/production.sqlite3
23
+ database: db/production.sqlite3
24
24
  pool: 5
25
25
  timeout: 5000
@@ -1,14 +1,16 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require File.expand_path('boot', __dir__)
2
2
 
3
3
  require 'active_record'
4
4
 
5
5
  Bundler.require(:default, ENV['RAILS_ENV'])
6
6
 
7
7
  # Load application files
8
- Dir["#{File.dirname(__FILE__)}/../app/**/*.rb"].each { |f| require f }
8
+ Dir["#{__dir__}/../app/**/*.rb"].each { |f| require f }
9
9
 
10
10
  # Load the database configuration
11
- config_file = File.expand_path('../database.yml', __FILE__)
12
- config = YAML::load_file(config_file)[ENV['RAILS_ENV']]
11
+ config_file = File.expand_path('database.yml', __dir__)
12
+ config = YAML.load_file(config_file)[ENV['RAILS_ENV']]
13
+
14
+ ActiveRecord::Base.logger = Logger.new(File::NULL)
13
15
 
14
16
  ActiveRecord::Base.establish_connection(config)
@@ -1,4 +1,4 @@
1
- class CreateTasks < ActiveRecord::Migration
1
+ class CreateTasks < ACTIVE_RECORD_MIGRATION_CLASS
2
2
  def change
3
3
  create_table :tasks do |t|
4
4
  t.datetime :completed_at
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
@@ -9,20 +8,14 @@
9
8
  # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
9
  # you'll amass, the slower it'll run and the greater likelihood for issues).
11
10
  #
12
- # It's strongly recommended to check this file into your version control system.
11
+ # It's strongly recommended that you check this file into your version control system.
13
12
 
14
- ActiveRecord::Schema.define(:version => 20170103215307) do
13
+ ActiveRecord::Schema.define(version: 2015_08_13_132804) do
15
14
 
16
- create_table "tasks", :force => true do |t|
15
+ create_table "tasks", force: :cascade do |t|
17
16
  t.datetime "completed_at"
18
- t.datetime "created_at", :null => false
19
- t.datetime "updated_at", :null => false
20
- end
21
-
22
- create_table "users", :force => true do |t|
23
- t.datetime "email_confirmed_at"
24
- t.datetime "created_at", :null => false
25
- t.datetime "updated_at", :null => false
17
+ t.datetime "created_at", null: false
18
+ t.datetime "updated_at", null: false
26
19
  end
27
20
 
28
21
  end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'generators/active_record/event/event_generator'
3
+
4
+ RSpec.describe ActiveRecord::Generators::EventGenerator, type: :generator do
5
+ arguments %w[task complete --field-type=date --skip-scopes]
6
+ destination File.expand_path('../../../../tmp', __dir__)
7
+
8
+ before { prepare_destination }
9
+
10
+ it 'generates a migration file' do
11
+ run_generator
12
+
13
+ assert_migration 'db/migrate/add_completed_on_to_tasks' do |migration|
14
+ assert_instance_method :change, migration do |content|
15
+ assert_match 'add_column :tasks, :completed_on, :date', content
16
+ end
17
+ end
18
+ end
19
+
20
+ context 'when the model file exists' do
21
+ before do
22
+ write_file 'app/models/task.rb', <<-RUBY.strip_heredoc
23
+ class Task < ActiveRecord::Base
24
+ end
25
+ RUBY
26
+ end
27
+
28
+ it 'updates the model file' do
29
+ run_generator
30
+
31
+ assert_file 'app/models/task.rb', <<-RUBY.strip_heredoc
32
+ class Task < ActiveRecord::Base
33
+ has_event :complete, field_type: :date, skip_scopes: true
34
+ end
35
+ RUBY
36
+ end
37
+ end
38
+
39
+ context "when the model file doesn't exist" do
40
+ it "doesn't create the model file" do
41
+ run_generator
42
+ assert_no_file 'app/models/task.rb'
43
+ end
44
+ end
45
+ end
@@ -1,20 +1,20 @@
1
1
  ENV['RAILS_ENV'] ||= 'test'
2
2
 
3
- require File.expand_path('../dummy/config/environment.rb', __FILE__)
3
+ require 'bundler/setup'
4
+ require 'coveralls'
5
+
6
+ Coveralls.wear!
7
+
8
+ require File.expand_path('dummy/config/environment.rb', __dir__)
4
9
 
5
10
  require 'factory_girl'
11
+ require 'generator_spec'
6
12
  require 'timecop'
13
+ require 'zonebie/rspec'
7
14
 
8
- # Load support files
9
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
15
+ Dir["#{__dir__}/support/**/*.rb"].each { |f| require f }
10
16
 
11
17
  RSpec.configure do |config|
12
- config.color = true
13
- config.order = :random
14
-
15
18
  config.include FactoryGirl::Syntax::Methods
16
-
17
- config.around(:each) do |example|
18
- Timecop.freeze { example.run }
19
- end
19
+ config.include GeneratorHelpers, type: :generator
20
20
  end
@@ -1,4 +1,3 @@
1
1
  FactoryGirl.define do
2
2
  factory :task
3
- factory :user
4
3
  end
@@ -0,0 +1,8 @@
1
+ module GeneratorHelpers
2
+ def write_file(file_name, contents)
3
+ file_path = File.expand_path(file_name, destination_root)
4
+
5
+ FileUtils.mkdir_p(File.dirname(file_path))
6
+ File.write(file_path, contents)
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :have_method do |expected|
2
+ match do |actual|
3
+ actual.public_instance_methods.include?(expected)
4
+ end
5
+ end
metadata CHANGED
@@ -1,127 +1,169 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-events
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Pieńkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-06 00:00:00.000000000 Z
11
+ date: 2020-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: verbs
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.1'
33
+ version: '2.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.1'
40
+ version: '2.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '2.2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '2.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: standalone_migrations
56
+ name: coveralls
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '0.8'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '0.8'
69
69
  - !ruby/object:Gem::Dependency
70
- name: sqlite3
70
+ name: factory_girl
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.8.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.8.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: generator_spec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ! '>='
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: '0.9'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ! '>='
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: '0.9'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rspec
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ! '>='
101
+ - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: '3.9'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ! '>='
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: '3.9'
97
111
  - !ruby/object:Gem::Dependency
98
- name: factory_girl
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.50.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.50.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
- - - ! '>='
129
+ - - "~>"
102
130
  - !ruby/object:Gem::Version
103
- version: '0'
131
+ version: '1.3'
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
- - - ! '>='
136
+ - - "~>"
109
137
  - !ruby/object:Gem::Version
110
- version: '0'
138
+ version: '1.3'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: timecop
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
- - - ! '>='
143
+ - - "~>"
116
144
  - !ruby/object:Gem::Version
117
- version: '0'
145
+ version: '0.9'
118
146
  type: :development
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
- - - ! '>='
150
+ - - "~>"
123
151
  - !ruby/object:Gem::Version
124
- version: '0'
152
+ version: '0.9'
153
+ - !ruby/object:Gem::Dependency
154
+ name: zonebie
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.6'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.6'
125
167
  description: An ActiveRecord extension providing convenience methods for timestamp
126
168
  management.
127
169
  email: pienkowb@gmail.com
@@ -129,26 +171,32 @@ executables: []
129
171
  extensions: []
130
172
  extra_rdoc_files: []
131
173
  files:
132
- - MIT-LICENSE
174
+ - LICENSE
133
175
  - README.md
134
176
  - Rakefile
135
177
  - lib/active_record/events.rb
178
+ - lib/active_record/events/extension.rb
179
+ - lib/active_record/events/macro.rb
180
+ - lib/active_record/events/method_factory.rb
136
181
  - lib/active_record/events/naming.rb
137
182
  - lib/active_record/events/version.rb
183
+ - lib/generators/active_record/event/USAGE
184
+ - lib/generators/active_record/event/event_generator.rb
185
+ - spec/active_record/events/macro_spec.rb
186
+ - spec/active_record/events/method_factory_spec.rb
138
187
  - spec/active_record/events/naming_spec.rb
139
188
  - spec/active_record/events_spec.rb
140
189
  - spec/dummy/app/models/task.rb
141
- - spec/dummy/app/models/user.rb
142
190
  - spec/dummy/config/boot.rb
143
191
  - spec/dummy/config/database.yml
144
192
  - spec/dummy/config/environment.rb
145
- - spec/dummy/db/development.sqlite3
146
193
  - spec/dummy/db/migrate/20150813132804_create_tasks.rb
147
- - spec/dummy/db/migrate/20170103215307_create_users.rb
148
194
  - spec/dummy/db/schema.rb
149
- - spec/dummy/db/test.sqlite3
195
+ - spec/generators/active_record/event/event_generator_spec.rb
150
196
  - spec/spec_helper.rb
151
- - spec/support/factories.rb
197
+ - spec/support/factories/task_factory.rb
198
+ - spec/support/helpers/generator_helpers.rb
199
+ - spec/support/matchers/have_method.rb
152
200
  homepage: https://github.com/pienkowb/active_record-events
153
201
  licenses:
154
202
  - MIT
@@ -159,32 +207,32 @@ require_paths:
159
207
  - lib
160
208
  required_ruby_version: !ruby/object:Gem::Requirement
161
209
  requirements:
162
- - - ! '>='
210
+ - - ">="
163
211
  - !ruby/object:Gem::Version
164
- version: 1.9.3
212
+ version: 2.0.0
165
213
  required_rubygems_version: !ruby/object:Gem::Requirement
166
214
  requirements:
167
- - - ! '>='
215
+ - - ">="
168
216
  - !ruby/object:Gem::Version
169
217
  version: '0'
170
218
  requirements: []
171
- rubyforge_project:
172
- rubygems_version: 2.4.8
219
+ rubygems_version: 3.0.3
173
220
  signing_key:
174
221
  specification_version: 4
175
222
  summary: Manage timestamps in ActiveRecord models
176
223
  test_files:
177
- - spec/active_record/events/naming_spec.rb
178
- - spec/active_record/events_spec.rb
224
+ - spec/spec_helper.rb
179
225
  - spec/dummy/app/models/task.rb
180
- - spec/dummy/app/models/user.rb
181
- - spec/dummy/config/boot.rb
182
- - spec/dummy/config/database.yml
183
226
  - spec/dummy/config/environment.rb
184
- - spec/dummy/db/development.sqlite3
185
- - spec/dummy/db/migrate/20150813132804_create_tasks.rb
186
- - spec/dummy/db/migrate/20170103215307_create_users.rb
227
+ - spec/dummy/config/database.yml
228
+ - spec/dummy/config/boot.rb
187
229
  - spec/dummy/db/schema.rb
188
- - spec/dummy/db/test.sqlite3
189
- - spec/spec_helper.rb
190
- - spec/support/factories.rb
230
+ - spec/dummy/db/migrate/20150813132804_create_tasks.rb
231
+ - spec/active_record/events/method_factory_spec.rb
232
+ - spec/active_record/events/naming_spec.rb
233
+ - spec/active_record/events/macro_spec.rb
234
+ - spec/active_record/events_spec.rb
235
+ - spec/support/factories/task_factory.rb
236
+ - spec/support/matchers/have_method.rb
237
+ - spec/support/helpers/generator_helpers.rb
238
+ - spec/generators/active_record/event/event_generator_spec.rb