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.
- checksums.yaml +5 -13
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/README.md +132 -14
- data/Rakefile +27 -3
- data/lib/active_record/events.rb +6 -32
- data/lib/active_record/events/extension.rb +19 -0
- data/lib/active_record/events/macro.rb +36 -0
- data/lib/active_record/events/method_factory.rb +84 -0
- data/lib/active_record/events/naming.rb +38 -8
- data/lib/active_record/events/version.rb +1 -1
- data/lib/generators/active_record/event/USAGE +15 -0
- data/lib/generators/active_record/event/event_generator.rb +60 -0
- data/spec/active_record/events/macro_spec.rb +49 -0
- data/spec/active_record/events/method_factory_spec.rb +59 -0
- data/spec/active_record/events/naming_spec.rb +64 -23
- data/spec/active_record/events_spec.rb +36 -10
- data/spec/dummy/app/models/task.rb +11 -0
- data/spec/dummy/config/boot.rb +4 -3
- data/spec/dummy/config/database.yml +3 -3
- data/spec/dummy/config/environment.rb +6 -4
- data/spec/dummy/db/migrate/20150813132804_create_tasks.rb +1 -1
- data/spec/dummy/db/schema.rb +5 -12
- data/spec/generators/active_record/event/event_generator_spec.rb +45 -0
- data/spec/spec_helper.rb +10 -10
- data/spec/support/{factories.rb → factories/task_factory.rb} +0 -1
- data/spec/support/helpers/generator_helpers.rb +8 -0
- data/spec/support/matchers/have_method.rb +5 -0
- metadata +107 -59
- data/spec/dummy/app/models/user.rb +0 -3
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20170103215307_create_users.rb +0 -9
- data/spec/dummy/db/test.sqlite3 +0 -0
@@ -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
|
data/spec/dummy/config/boot.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
2
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('
|
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
|
-
|
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:
|
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:
|
17
|
+
database: db/test.sqlite3
|
18
18
|
pool: 5
|
19
19
|
timeout: 5000
|
20
20
|
|
21
21
|
production:
|
22
22
|
adapter: sqlite3
|
23
|
-
database:
|
23
|
+
database: db/production.sqlite3
|
24
24
|
pool: 5
|
25
25
|
timeout: 5000
|
@@ -1,14 +1,16 @@
|
|
1
|
-
require File.expand_path('
|
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["#{
|
8
|
+
Dir["#{__dir__}/../app/**/*.rb"].each { |f| require f }
|
9
9
|
|
10
10
|
# Load the database configuration
|
11
|
-
config_file = File.expand_path('
|
12
|
-
config = YAML
|
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)
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -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
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
12
|
|
14
|
-
ActiveRecord::Schema.define(:
|
13
|
+
ActiveRecord::Schema.define(version: 2015_08_13_132804) do
|
15
14
|
|
16
|
-
create_table "tasks", :
|
15
|
+
create_table "tasks", force: :cascade do |t|
|
17
16
|
t.datetime "completed_at"
|
18
|
-
t.datetime "created_at",
|
19
|
-
t.datetime "updated_at",
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
ENV['RAILS_ENV'] ||= 'test'
|
2
2
|
|
3
|
-
require
|
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
|
-
#
|
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
|
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:
|
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:
|
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: '
|
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: '
|
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.
|
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.
|
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: '
|
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: '
|
54
|
+
version: '2.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
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:
|
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: '
|
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: '
|
110
|
+
version: '3.9'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
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: '
|
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: '
|
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
|
-
-
|
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/
|
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:
|
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
|
-
|
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/
|
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/
|
185
|
-
- spec/dummy/
|
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/
|
189
|
-
- spec/
|
190
|
-
- spec/
|
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
|