deferring 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - rbx-2
7
+ - jruby-19mode
8
+ - ruby-head
9
+ - jruby-head
10
+
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: jruby-19mode
14
+ - rvm: ruby-head
15
+ - rvm: jruby-head
16
+
17
+ gemfile:
18
+ - gemfiles/rails_30.gemfile
19
+ - gemfiles/rails_32.gemfile
20
+ - gemfiles/rails_40.gemfile
21
+ - gemfiles/rails_41.gemfile
22
+
23
+ script: 'bundle exec rake'
data/README.md CHANGED
@@ -1,9 +1,12 @@
1
1
  # Deferring
2
2
 
3
+ [![Build Status](http://img.shields.io/travis/robinroestenburg/deferring.svg?style=flat)](https://travis-ci.org/robinroestenburg/deferring)
4
+ [![Gem Version](http://img.shields.io/gem/v/deferring.svg?style=flat)](https://rubygems.org/gems/deferring)
5
+
3
6
  Deferring makes it possible to delay saving ActiveRecord associations until the
4
7
  parent object has been saved.
5
8
 
6
- Currently supporting Rails 3.0, 3.2, 4.0 and 4.1 on Ruby 1.9.3.
9
+ Currently supporting Rails 3.0, 3.2, 4.0 & 4.1 on Ruby 1.9.3, 2.0.0 & 2.1.0.
7
10
 
8
11
  It is important to note that Deferring does not touch the original `has_many`
9
12
  and `has_and_belongs_to_many` associations. You can use them, without worrying
@@ -1,5 +1,5 @@
1
1
  PATH
2
- remote: ..
2
+ remote: ../
3
3
  specs:
4
4
  deferring (0.0.1)
5
5
  activerecord (> 3.0)
@@ -24,16 +24,20 @@ GEM
24
24
  arel (2.0.10)
25
25
  builder (2.1.2)
26
26
  diff-lcs (1.2.5)
27
- i18n (0.5.2)
28
- rake (10.3.1)
29
- rspec (2.14.1)
30
- rspec-core (~> 2.14.0)
31
- rspec-expectations (~> 2.14.0)
32
- rspec-mocks (~> 2.14.0)
33
- rspec-core (2.14.8)
34
- rspec-expectations (2.14.5)
35
- diff-lcs (>= 1.1.3, < 2.0)
36
- rspec-mocks (2.14.6)
27
+ i18n (0.5.4)
28
+ rake (10.3.2)
29
+ rspec (3.0.0)
30
+ rspec-core (~> 3.0.0)
31
+ rspec-expectations (~> 3.0.0)
32
+ rspec-mocks (~> 3.0.0)
33
+ rspec-core (3.0.0)
34
+ rspec-support (~> 3.0.0)
35
+ rspec-expectations (3.0.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.0.0)
38
+ rspec-mocks (3.0.0)
39
+ rspec-support (~> 3.0.0)
40
+ rspec-support (3.0.0)
37
41
  sqlite3 (1.3.9)
38
42
  thor (0.19.1)
39
43
  tzinfo (0.3.39)
@@ -1,5 +1,5 @@
1
1
  PATH
2
- remote: ..
2
+ remote: ../
3
3
  specs:
4
4
  deferring (0.0.1)
5
5
  activerecord (> 3.0)
@@ -26,16 +26,20 @@ GEM
26
26
  builder (3.0.4)
27
27
  diff-lcs (1.2.5)
28
28
  i18n (0.6.9)
29
- multi_json (1.9.2)
30
- rake (10.3.1)
31
- rspec (2.14.1)
32
- rspec-core (~> 2.14.0)
33
- rspec-expectations (~> 2.14.0)
34
- rspec-mocks (~> 2.14.0)
35
- rspec-core (2.14.8)
36
- rspec-expectations (2.14.5)
37
- diff-lcs (>= 1.1.3, < 2.0)
38
- rspec-mocks (2.14.6)
29
+ multi_json (1.10.1)
30
+ rake (10.3.2)
31
+ rspec (3.0.0)
32
+ rspec-core (~> 3.0.0)
33
+ rspec-expectations (~> 3.0.0)
34
+ rspec-mocks (~> 3.0.0)
35
+ rspec-core (3.0.0)
36
+ rspec-support (~> 3.0.0)
37
+ rspec-expectations (3.0.0)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.0.0)
40
+ rspec-mocks (3.0.0)
41
+ rspec-support (~> 3.0.0)
42
+ rspec-support (3.0.0)
39
43
  sqlite3 (1.3.9)
40
44
  thor (0.19.1)
41
45
  tzinfo (0.3.39)
@@ -31,19 +31,23 @@ GEM
31
31
  diff-lcs (1.2.5)
32
32
  i18n (0.6.9)
33
33
  minitest (4.7.5)
34
- multi_json (1.9.2)
35
- rake (10.3.1)
36
- rspec (2.14.1)
37
- rspec-core (~> 2.14.0)
38
- rspec-expectations (~> 2.14.0)
39
- rspec-mocks (~> 2.14.0)
40
- rspec-core (2.14.8)
41
- rspec-expectations (2.14.5)
42
- diff-lcs (>= 1.1.3, < 2.0)
43
- rspec-mocks (2.14.6)
34
+ multi_json (1.10.1)
35
+ rake (10.3.2)
36
+ rspec (3.0.0)
37
+ rspec-core (~> 3.0.0)
38
+ rspec-expectations (~> 3.0.0)
39
+ rspec-mocks (~> 3.0.0)
40
+ rspec-core (3.0.0)
41
+ rspec-support (~> 3.0.0)
42
+ rspec-expectations (3.0.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.0.0)
45
+ rspec-mocks (3.0.0)
46
+ rspec-support (~> 3.0.0)
47
+ rspec-support (3.0.0)
44
48
  sqlite3 (1.3.9)
45
49
  thor (0.19.1)
46
- thread_safe (0.3.3)
50
+ thread_safe (0.3.4)
47
51
  tzinfo (0.3.39)
48
52
 
49
53
  PLATFORMS
@@ -29,20 +29,24 @@ GEM
29
29
  diff-lcs (1.2.5)
30
30
  i18n (0.6.9)
31
31
  json (1.8.1)
32
- minitest (5.3.3)
33
- rake (10.3.1)
34
- rspec (2.14.1)
35
- rspec-core (~> 2.14.0)
36
- rspec-expectations (~> 2.14.0)
37
- rspec-mocks (~> 2.14.0)
38
- rspec-core (2.14.8)
39
- rspec-expectations (2.14.5)
40
- diff-lcs (>= 1.1.3, < 2.0)
41
- rspec-mocks (2.14.6)
32
+ minitest (5.3.4)
33
+ rake (10.3.2)
34
+ rspec (3.0.0)
35
+ rspec-core (~> 3.0.0)
36
+ rspec-expectations (~> 3.0.0)
37
+ rspec-mocks (~> 3.0.0)
38
+ rspec-core (3.0.0)
39
+ rspec-support (~> 3.0.0)
40
+ rspec-expectations (3.0.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.0.0)
43
+ rspec-mocks (3.0.0)
44
+ rspec-support (~> 3.0.0)
45
+ rspec-support (3.0.0)
42
46
  sqlite3 (1.3.9)
43
47
  thor (0.19.1)
44
- thread_safe (0.3.3)
45
- tzinfo (1.1.0)
48
+ thread_safe (0.3.4)
49
+ tzinfo (1.2.1)
46
50
  thread_safe (~> 0.1)
47
51
 
48
52
  PLATFORMS
data/lib/deferring.rb CHANGED
@@ -111,9 +111,6 @@ module Deferring
111
111
  # Send the objects of our delegated association to the original
112
112
  # association and store the result.
113
113
  send(:"original_#{association_name}=", send(:"deferred_#{association_name}").objects)
114
- send(:"deferred_#{association_name}").objects.each do |record|
115
- record.run_callbacks :commit
116
- end
117
114
 
118
115
  # Store the new value of the association into our delegated association.
119
116
  send(
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Deferring
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'deferred has-many association' do
4
+
5
+ before(:each) do
6
+ Person.create!(name: 'Alice')
7
+ Person.create!(name: 'Bob')
8
+
9
+ Issue.create!(subject: 'Printer PRT-001 jammed')
10
+ Issue.create!(subject: 'Database server DB-1337 down')
11
+ Issue.create!(subject: 'Make me a sandwich!')
12
+ end
13
+
14
+ let(:printer_issue) { Issue.where(subject: 'Printer PRT-001 jammed').first }
15
+ let(:db_issue) { Issue.where(subject: 'Database server DB-1337 down').first }
16
+ let(:sandwich_issue) { Issue.where(subject: 'Make me a sandwich!').first }
17
+
18
+ describe 'preloading associations' do
19
+ before do
20
+ p = Person.find(1)
21
+ p.issues << printer_issue << db_issue
22
+ p.save!
23
+ end
24
+
25
+ if rails30 # old-style preload
26
+ it 'should have loaded the association' do
27
+ p = Person.find(1)
28
+ Person.send(:preload_associations, p, [:issues])
29
+ expect(p.issues.loaded?).to be_truthy
30
+ expect(p.issue_ids).to eq [printer_issue.id, db_issue.id]
31
+ end
32
+ end
33
+
34
+ if rails32 || rails4
35
+ it 'should have loaded the association when pre-loading' do
36
+ people = Person.preload(:issues)
37
+ expect(people[0].issues.loaded?).to be_truthy
38
+ expect(people[0].issue_ids).to eq [printer_issue.id, db_issue.id]
39
+ end
40
+
41
+ it 'should have loaded the association when eager loading' do
42
+ people = Person.eager_load(:issues)
43
+ expect(people[0].issues.loaded?).to be_truthy
44
+ expect(people[0].issue_ids).to eq [db_issue.id, printer_issue.id]
45
+ end
46
+
47
+ it 'should have loaded the association when joining' do
48
+ people = Person.includes(:issues).all
49
+ expect(people[0].issues.loaded?).to be_truthy
50
+ expect(people[0].issue_ids).to eq [printer_issue.id, db_issue.id]
51
+ end
52
+ end
53
+
54
+ it 'should not have loaded the association when using a regular query' do
55
+ people = Person.all
56
+ expect(people[0].issues.loaded?).to be_falsey
57
+ end
58
+ end
59
+
60
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'deferred has-and-belongs-to-many associations' do
3
+ RSpec.describe 'deferred has-and-belongs-to-many associations' do
4
4
 
5
5
  before :each do
6
6
  Person.create!(name: 'Alice')
@@ -122,8 +122,8 @@ describe 'deferred has-and-belongs-to-many associations' do
122
122
  dba = Team.first
123
123
  dba.people = [Person.first, Person.find(2), Person.last]
124
124
 
125
- dba.people.size.should eq 2
126
- dba.person_ids.should eq [1,2]
125
+ expect(dba.people.size).to eq 2
126
+ expect(dba.person_ids).to eq [1,2]
127
127
  end
128
128
  end
129
129
 
@@ -140,7 +140,7 @@ describe 'deferred has-and-belongs-to-many associations' do
140
140
  it 'loads the association' do
141
141
  person = Person.where(name: 'Bob').first
142
142
  Person.send(:preload_associations, person, [:teams])
143
- expect(person.teams.loaded?).to be_true
143
+ expect(person.teams.loaded?).to be_truthy
144
144
  expect(person.team_ids).to eq [dba.id, support.id]
145
145
  end
146
146
  end
@@ -148,26 +148,26 @@ describe 'deferred has-and-belongs-to-many associations' do
148
148
  if rails32 || rails4
149
149
  it 'loads the association when pre-loading' do
150
150
  person = Person.preload(:teams).where(name: 'Bob').first
151
- expect(person.teams.loaded?).to be_true
151
+ expect(person.teams.loaded?).to be_truthy
152
152
  expect(person.team_ids).to eq [dba.id, support.id]
153
153
  end
154
154
 
155
155
  it 'loads the association when eager loading' do
156
156
  person = Person.eager_load(:teams).where(name: 'Bob').first
157
- expect(person.teams.loaded?).to be_true
157
+ expect(person.teams.loaded?).to be_truthy
158
158
  expect(person.team_ids).to eq [dba.id, support.id]
159
159
  end
160
160
 
161
161
  it 'loads the association when joining' do
162
162
  person = Person.includes(:teams).where(name: 'Bob').first
163
- expect(person.teams.loaded?).to be_true
163
+ expect(person.teams.loaded?).to be_truthy
164
164
  expect(person.team_ids).to eq [dba.id, support.id]
165
165
  end
166
166
  end
167
167
 
168
168
  it 'does not load the association when using a regular query' do
169
169
  person = Person.where(name: 'Bob').first
170
- expect(person.teams.loaded?).to be_false
170
+ expect(person.teams.loaded?).to be_falsey
171
171
  end
172
172
 
173
173
  end
@@ -408,11 +408,11 @@ describe 'deferred has-and-belongs-to-many associations' do
408
408
  p.teams = [Team.first, Team.find(3)]
409
409
  p.save
410
410
  teams = Person.first.teams
411
- teams.loaded?.should == false
412
- teams.find(3).should == Team.find(3)
413
- teams.first.should == Team.first
414
- teams.last.should == Team.find(3)
415
- teams.loaded?.should == false
411
+ expect(teams.loaded?).to eq(false)
412
+ expect(teams.find(3)).to eq(Team.find(3))
413
+ expect(teams.first).to eq(Team.first)
414
+ expect(teams.last).to eq(Team.find(3))
415
+ expect(teams.loaded?).to eq(false)
416
416
  end
417
417
 
418
418
  end
@@ -427,13 +427,13 @@ describe 'deferred has-and-belongs-to-many associations' do
427
427
  bob.teams << Team.find(2)
428
428
  bob.save!
429
429
 
430
- bob.audit_log.length.should == 4
431
- bob.audit_log.should == [
430
+ expect(bob.audit_log.length).to eq(4)
431
+ expect(bob.audit_log).to eq([
432
432
  'Before removing team 1',
433
433
  'After removing team 1',
434
434
  'Before adding team 2',
435
435
  'After adding team 2'
436
- ]
436
+ ])
437
437
  end
438
438
 
439
439
  describe 'accepts_nested_attributes' do
@@ -452,18 +452,18 @@ describe 'deferred has-and-belongs-to-many associations' do
452
452
  { id: 2, _destroy: true }
453
453
  ]
454
454
  }
455
- p.teams.length.should == 1
456
- p.team_ids.sort.should == [1]
455
+ expect(p.teams.length).to eq(1)
456
+ expect(p.team_ids.sort).to eq([1])
457
457
 
458
458
  Person.first
459
- Person.first.teams.length.should == 3
460
- Person.first.team_ids.sort.should == [1,2,3]
459
+ expect(Person.first.teams.length).to eq(3)
460
+ expect(Person.first.team_ids.sort).to eq([1,2,3])
461
461
 
462
462
  p.save!
463
463
 
464
464
  p = Person.first
465
- p.teams.length.should == 1
466
- p.team_ids.sort.should == [1]
465
+ expect(p.teams.length).to eq(1)
466
+ expect(p.team_ids.sort).to eq([1])
467
467
  end
468
468
 
469
469
  it 'should mass assign' do
@@ -478,18 +478,18 @@ describe 'deferred has-and-belongs-to-many associations' do
478
478
  { id: 3, _destroy: true },
479
479
  { id: 2, _destroy: true }
480
480
  ]
481
- p.teams.length.should == 1
482
- p.team_ids.sort.should == [1]
481
+ expect(p.teams.length).to eq(1)
482
+ expect(p.team_ids.sort).to eq([1])
483
483
 
484
484
  Person.first
485
- Person.first.teams.length.should == 3
486
- Person.first.team_ids.sort.should == [1,2,3]
485
+ expect(Person.first.teams.length).to eq(3)
486
+ expect(Person.first.team_ids.sort).to eq([1,2,3])
487
487
 
488
488
  p.save!
489
489
 
490
490
  p = Person.first
491
- p.teams.length.should == 1
492
- p.team_ids.sort.should == [1]
491
+ expect(p.teams.length).to eq(1)
492
+ expect(p.team_ids.sort).to eq([1])
493
493
  end
494
494
  end
495
495
 
@@ -518,8 +518,8 @@ describe 'deferred has-and-belongs-to-many associations' do
518
518
  expect(bob).to_not be_valid
519
519
  expect(alice).to_not be_valid
520
520
 
521
- expect(bob.save).to be_false
522
- expect(alice.save).to be_false
521
+ expect(bob.save).to be_falsey
522
+ expect(alice.save).to be_falsey
523
523
  end
524
524
 
525
525
  xit 'does not validate records when validate: false' do
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,8 @@ require 'support/models'
4
4
  require 'support/rails_versions'
5
5
 
6
6
  RSpec.configure do |config|
7
- config.treat_symbols_as_metadata_keys_with_true_values = true
7
+ config.disable_monkey_patching!
8
+
8
9
  config.run_all_when_everything_filtered = true
9
10
  config.filter_run :focus
10
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deferring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-27 00:00:00.000000000 Z
12
+ date: 2014-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -117,6 +117,7 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - .gitignore
119
119
  - .rspec
120
+ - .travis.yml
120
121
  - Appraisals
121
122
  - Gemfile
122
123
  - LICENSE.txt
@@ -136,6 +137,7 @@ files:
136
137
  - lib/deferring.rb
137
138
  - lib/deferring/deferred_association.rb
138
139
  - lib/deferring/version.rb
140
+ - spec/lib/deferring_has_many_spec.rb
139
141
  - spec/lib/deferring_spec.rb
140
142
  - spec/spec_helper.rb
141
143
  - spec/support/active_record.rb
@@ -167,6 +169,7 @@ signing_key:
167
169
  specification_version: 3
168
170
  summary: Defer saving ActiveRecord associations until parent is saved
169
171
  test_files:
172
+ - spec/lib/deferring_has_many_spec.rb
170
173
  - spec/lib/deferring_spec.rb
171
174
  - spec/spec_helper.rb
172
175
  - spec/support/active_record.rb