changeling 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,76 +17,76 @@ describe Changeling::Probeling do
17
17
  end
18
18
  end
19
19
 
20
- @object.all_history.count.should == 4
20
+ @object.all_loglings.count.should == 4
21
21
  end
22
22
  end
23
23
 
24
- describe ".all_history" do
24
+ describe ".all_loglings" do
25
25
  it "should query Logling with it's class name, and it's own ID" do
26
26
  @klass.should_receive(:records_for).with(@object)
27
- @object.all_history
27
+ @object.all_loglings
28
28
  end
29
29
 
30
30
  it "should return an array of Loglings" do
31
- @object.all_history.map(&:class).uniq.should == [@klass]
31
+ @object.all_loglings.map(&:class).uniq.should == [@klass]
32
32
  end
33
33
  end
34
34
 
35
- describe ".history" do
35
+ describe ".loglings" do
36
36
  it "should query Logling with it's class name, and it's own ID, and a default number of loglings to return" do
37
37
  @klass.should_receive(:records_for).with(@object, 10)
38
- @object.history
38
+ @object.loglings
39
39
  end
40
40
 
41
41
  it "should take an argument that overrides the default" do
42
42
  @klass.should_receive(:records_for).with(@object, 5)
43
- @object.history(5)
43
+ @object.loglings(5)
44
44
  end
45
45
 
46
46
  it "should handle non-integer arguments" do
47
47
  @klass.should_receive(:records_for).with(@object, 5)
48
- @object.history("5")
48
+ @object.loglings("5")
49
49
  end
50
50
 
51
51
  it "should only return the amount of loglings requested" do
52
- @object.all_history.count.should == 4
53
- @object.history(2).count.should == 2
52
+ @object.all_loglings.count.should == 4
53
+ @object.loglings(2).count.should == 2
54
54
  end
55
55
 
56
56
  it "should not error out if the record count desired is more than the total number of loglings" do
57
- @object.history(20).count.should == 4
57
+ @object.loglings(20).count.should == 4
58
58
  end
59
59
  end
60
60
 
61
- describe ".history_for_field" do
61
+ describe ".loglings_for_field" do
62
62
  it "should query Logling with it's class name, and it's own ID, and a field name" do
63
63
  @klass.should_receive(:records_for).with(@object, nil, "field")
64
- @object.history_for_field("field")
64
+ @object.loglings_for_field("field")
65
65
  end
66
66
 
67
67
  it "should be able to take a length to specify amount of loglings to return" do
68
68
  @klass.should_receive(:records_for).with(@object, 5, "field")
69
- @object.history_for_field("field", 5)
69
+ @object.loglings_for_field("field", 5)
70
70
  end
71
71
 
72
72
  it "should handle non-integer arguments for length" do
73
73
  @klass.should_receive(:records_for).with(@object, 5, "field")
74
- @object.history_for_field("field", "5")
74
+ @object.loglings_for_field("field", "5")
75
75
  end
76
76
 
77
77
  it "should handle symbol arguments for field" do
78
78
  @klass.should_receive(:records_for).with(@object, nil, "field")
79
- @object.history_for_field(:field)
79
+ @object.loglings_for_field(:field)
80
80
  end
81
81
 
82
82
  it "should only return loglings where the specified field has changed" do
83
83
  models.values.each do |value|
84
84
  value[:changes].keys.each do |field|
85
- @object.history_for_field(field).each do |logling|
85
+ @object.loglings_for_field(field).each do |logling|
86
86
  logling.modifications.keys.should include(field)
87
87
  end
88
88
 
89
- @object.history_for_field(field).count.should == 2
89
+ @object.loglings_for_field(field).count.should == 2
90
90
  end
91
91
  end
92
92
  end
@@ -117,10 +117,10 @@ describe Changeling::Probeling do
117
117
  value[:changes].keys.each do |field|
118
118
  # Reverse chronological order: first object is the last inserted, which should have 2 changes.
119
119
  # The last object should have 1 change.
120
- @object.history_for_field(field).last.modifications.keys.count.should == 1
121
- @object.history_for_field(field).first.modifications.keys.count.should == 2
120
+ @object.loglings_for_field(field).last.modifications.keys.count.should == 1
121
+ @object.loglings_for_field(field).first.modifications.keys.count.should == 2
122
122
 
123
- @object.history_for_field(field).count.should == 3
123
+ @object.loglings_for_field(field).count.should == 3
124
124
  end
125
125
  end
126
126
  end
@@ -128,8 +128,8 @@ describe Changeling::Probeling do
128
128
  it "should only return the specified amount of loglings" do
129
129
  models.values.each do |value|
130
130
  value[:changes].keys.each do |field|
131
- @object.history_for_field(field).count.should == 2
132
- @object.history_for_field(field, 1).count.should == 1
131
+ @object.loglings_for_field(field).count.should == 2
132
+ @object.loglings_for_field(field, 1).count.should == 1
133
133
  end
134
134
  end
135
135
  end
@@ -137,8 +137,8 @@ describe Changeling::Probeling do
137
137
  it "should not error out if the record count desired is more than the total number of loglings" do
138
138
  models.values.each do |value|
139
139
  value[:changes].keys.each do |field|
140
- @object.history_for_field(field).count.should == 2
141
- @object.history_for_field(field, 10).count.should == 2
140
+ @object.loglings_for_field(field).count.should == 2
141
+ @object.loglings_for_field(field, 10).count.should == 2
142
142
  end
143
143
  end
144
144
  end
@@ -10,30 +10,32 @@ describe Changeling::Trackling do
10
10
  @object = model.new(args[:options])
11
11
  end
12
12
 
13
- describe "callbacks" do
14
- it "should not create a logling when doing the initial save of a new object" do
15
- @klass.should_not_receive(:create)
16
- @object.run_callbacks(:create)
17
- end
18
-
19
- context "after_update" do
20
- it "should create a logling when updating an object and changes are made" do
21
- @klass.should_receive(:create)
22
- @object.stub(:changes).and_return({ :field => 'value' })
23
- end
24
-
25
- it "should create a logling when updating an object and changes are empty" do
13
+ context "#{model}" do
14
+ describe "callbacks" do
15
+ it "should not create a logling when doing the initial save of a new object" do
26
16
  @klass.should_not_receive(:create)
27
- @object.stub(:changes).and_return({})
17
+ @object.run_callbacks(:create)
28
18
  end
29
19
 
30
- it "should not create a logling when updating an object and no changes have been made" do
31
- @klass.should_not_receive(:create)
32
- @object.stub(:changes).and_return(nil)
33
- end
20
+ context "after_update" do
21
+ it "should create a logling when updating an object and changes are made" do
22
+ @klass.should_receive(:create)
23
+ @object.stub(:changes).and_return({ :field => 'value' })
24
+ end
25
+
26
+ it "should not create a logling when updating an object and changes are empty" do
27
+ @klass.should_not_receive(:create)
28
+ @object.stub(:changes).and_return({})
29
+ end
30
+
31
+ it "should not create a logling when updating an object and no changes have been made" do
32
+ @klass.should_not_receive(:create)
33
+ @object.stub(:changes).and_return(nil)
34
+ end
34
35
 
35
- after(:each) do
36
- @object.run_callbacks(:update)
36
+ after(:each) do
37
+ @object.run_callbacks(:update)
38
+ end
37
39
  end
38
40
  end
39
41
  end
@@ -23,12 +23,18 @@ ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => ":m
23
23
 
24
24
  ActiveRecord::Migration.verbose = false
25
25
  ActiveRecord::Schema.define(:version => 1) do
26
- # See the activerecord folder under spec/fixtures/models
26
+ # See the active_record models under spec/fixtures/models
27
27
  create_table :blog_post_active_records do |t|
28
28
  t.string :title
29
29
  t.string :content
30
30
  t.boolean :public
31
31
  end
32
+
33
+ create_table :async_blog_post_active_records do |t|
34
+ t.string :title
35
+ t.string :content
36
+ t.boolean :public
37
+ end
32
38
  end
33
39
 
34
40
  RSpec.configure do |config|
@@ -64,7 +70,7 @@ def clear_tire_indexes
64
70
  end
65
71
  end
66
72
 
67
- def models
73
+ def common_conditions
68
74
  hash = {
69
75
  :options => {
70
76
  :title => "Changeling",
@@ -76,10 +82,20 @@ def models
76
82
  "content" => ["Something about Changeling", "Content about Changeling"]
77
83
  }
78
84
  }
85
+ end
86
+
87
+ def models
88
+ @models = {
89
+ BlogPost => common_conditions,
90
+ BlogPostNoTimestamp => common_conditions,
91
+ BlogPostActiveRecord => common_conditions
92
+ }
93
+ end
79
94
 
95
+ def async_models
80
96
  @models = {
81
- BlogPost => hash,
82
- BlogPostNoTimestamp => hash,
83
- BlogPostActiveRecord => hash
97
+ AsyncBlogPost => common_conditions,
98
+ AsyncBlogPostNoTimestamp => common_conditions,
99
+ AsyncBlogPostActiveRecord => common_conditions
84
100
  }
85
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: changeling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,27 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-09 00:00:00.000000000Z
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tire
16
- requirement: &70321114835040 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.5.4
21
+ version: 0.5.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70321114835040
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.5.3
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activemodel
27
- requirement: &70321114834620 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,32 +37,47 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70321114834620
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: mongoid
38
- requirement: &70321114834080 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
- - - =
51
+ - - '='
42
52
  - !ruby/object:Gem::Version
43
53
  version: 2.4.1
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70321114834080
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.4.1
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: activerecord
49
- requirement: &70321114833580 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
- - - =
67
+ - - '='
53
68
  - !ruby/object:Gem::Version
54
69
  version: 3.1.3
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70321114833580
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 3.1.3
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: ruby-debug19
60
- requirement: &70321114833200 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70321114833200
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: rake
71
- requirement: &70321114832740 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70321114832740
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: rspec
82
- requirement: &70321105892520 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *70321105892520
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: rspec-rails
93
- requirement: &70321105892100 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>='
@@ -98,10 +133,15 @@ dependencies:
98
133
  version: '0'
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *70321105892100
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
102
142
  - !ruby/object:Gem::Dependency
103
143
  name: bson_ext
104
- requirement: &70321105891680 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ! '>='
@@ -109,10 +149,15 @@ dependencies:
109
149
  version: '0'
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *70321105891680
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
113
158
  - !ruby/object:Gem::Dependency
114
159
  name: database_cleaner
115
- requirement: &70321105891260 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
116
161
  none: false
117
162
  requirements:
118
163
  - - ! '>='
@@ -120,10 +165,15 @@ dependencies:
120
165
  version: '0'
121
166
  type: :development
122
167
  prerelease: false
123
- version_requirements: *70321105891260
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
124
174
  - !ruby/object:Gem::Dependency
125
175
  name: sqlite3
126
- requirement: &70321105890840 !ruby/object:Gem::Requirement
176
+ requirement: !ruby/object:Gem::Requirement
127
177
  none: false
128
178
  requirements:
129
179
  - - ! '>='
@@ -131,10 +181,15 @@ dependencies:
131
181
  version: '0'
132
182
  type: :development
133
183
  prerelease: false
134
- version_requirements: *70321105890840
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
135
190
  - !ruby/object:Gem::Dependency
136
191
  name: rails
137
- requirement: &70321105890420 !ruby/object:Gem::Requirement
192
+ requirement: !ruby/object:Gem::Requirement
138
193
  none: false
139
194
  requirements:
140
195
  - - ! '>='
@@ -142,7 +197,44 @@ dependencies:
142
197
  version: '0'
143
198
  type: :development
144
199
  prerelease: false
145
- version_requirements: *70321105890420
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ - !ruby/object:Gem::Dependency
207
+ name: sidekiq
208
+ requirement: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ type: :development
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ - !ruby/object:Gem::Dependency
223
+ name: resque
224
+ requirement: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
234
+ requirements:
235
+ - - ! '>='
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
146
238
  description: A simple, yet flexible solution to tracking changes made to objects in
147
239
  your database.
148
240
  email:
@@ -159,27 +251,35 @@ files:
159
251
  - LICENSE
160
252
  - README.md
161
253
  - Rakefile
254
+ - benchmarks/benchmark_setup.rake
255
+ - benchmarks/changeling_benchmark.rake
256
+ - benchmarks/tire_benchmark.rake
162
257
  - changeling.gemspec
163
258
  - lib/changeling.rb
259
+ - lib/changeling/async/resque_worker.rb
260
+ - lib/changeling/async/sidekiq_worker.rb
261
+ - lib/changeling/async/trackling.rb
164
262
  - lib/changeling/blameling.rb
263
+ - lib/changeling/exceptions/async_gem_required.rb
165
264
  - lib/changeling/models/logling.rb
166
265
  - lib/changeling/probeling.rb
167
266
  - lib/changeling/support/search.rb
168
267
  - lib/changeling/trackling.rb
169
268
  - lib/changeling/version.rb
170
269
  - spec/config/mongoid.yml
171
- - spec/controllers/blameling_controller_spec.rb
172
- - spec/controllers/blog_posts_controller_spec.rb
173
- - spec/controllers/current_account_controller_spec.rb
174
- - spec/controllers/no_current_user_controller_spec.rb
270
+ - spec/controllers/blameling_integration_spec.rb
175
271
  - spec/fixtures/app/application.rb
176
272
  - spec/fixtures/app/controllers/blameling_controller.rb
177
273
  - spec/fixtures/app/controllers/blog_posts_controller.rb
178
274
  - spec/fixtures/app/controllers/current_account_controller.rb
179
275
  - spec/fixtures/app/controllers/no_current_user_controller.rb
276
+ - spec/fixtures/app/models/async_blog_post.rb
277
+ - spec/fixtures/app/models/async_blog_post_active_record.rb
278
+ - spec/fixtures/app/models/async_blog_post_no_timestamp.rb
180
279
  - spec/fixtures/app/models/blog_post.rb
181
280
  - spec/fixtures/app/models/blog_post_active_record.rb
182
281
  - spec/fixtures/app/models/blog_post_no_timestamp.rb
282
+ - spec/lib/changeling/async/trackling_spec.rb
183
283
  - spec/lib/changeling/models/logling_spec.rb
184
284
  - spec/lib/changeling/probeling_spec.rb
185
285
  - spec/lib/changeling/support/search_spec.rb
@@ -205,24 +305,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
305
  version: '0'
206
306
  requirements: []
207
307
  rubyforge_project:
208
- rubygems_version: 1.8.15
308
+ rubygems_version: 1.8.24
209
309
  signing_key:
210
310
  specification_version: 3
211
311
  summary: Object change-logger
212
312
  test_files:
213
313
  - spec/config/mongoid.yml
214
- - spec/controllers/blameling_controller_spec.rb
215
- - spec/controllers/blog_posts_controller_spec.rb
216
- - spec/controllers/current_account_controller_spec.rb
217
- - spec/controllers/no_current_user_controller_spec.rb
314
+ - spec/controllers/blameling_integration_spec.rb
218
315
  - spec/fixtures/app/application.rb
219
316
  - spec/fixtures/app/controllers/blameling_controller.rb
220
317
  - spec/fixtures/app/controllers/blog_posts_controller.rb
221
318
  - spec/fixtures/app/controllers/current_account_controller.rb
222
319
  - spec/fixtures/app/controllers/no_current_user_controller.rb
320
+ - spec/fixtures/app/models/async_blog_post.rb
321
+ - spec/fixtures/app/models/async_blog_post_active_record.rb
322
+ - spec/fixtures/app/models/async_blog_post_no_timestamp.rb
223
323
  - spec/fixtures/app/models/blog_post.rb
224
324
  - spec/fixtures/app/models/blog_post_active_record.rb
225
325
  - spec/fixtures/app/models/blog_post_no_timestamp.rb
326
+ - spec/lib/changeling/async/trackling_spec.rb
226
327
  - spec/lib/changeling/models/logling_spec.rb
227
328
  - spec/lib/changeling/probeling_spec.rb
228
329
  - spec/lib/changeling/support/search_spec.rb