HornsAndHooves-flat_map 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f3b82b7ae0f88b1c76017b5ac2410dee62efeed
4
- data.tar.gz: 5f72a1ca80df379ddfd7dfeb22b8b8d1530c8b0f
3
+ metadata.gz: ae437e1e699d72bc1e9a7edae6fe93d2a4ef2074
4
+ data.tar.gz: e3dc282d44fb77ba18df155e4386372cba68941d
5
5
  SHA512:
6
- metadata.gz: 62115ee9279c68f7ed109ed43b769fb28669d9f6a3c884d69fb8680e41cc20b2139f2993578b73a9b79a924de5d790bde331755190d6f6fbd77467c3ad40f511
7
- data.tar.gz: 50f70f29acdc63ba0de90725f79694e877ca983dcd84bea897e9defa9c7463fcff6dd62ee48233e7981d55eae9e50735ec4ad23905c071f7d2a5f69ec29e558c
6
+ metadata.gz: adb627f3d5401014b077d9efbdcfb7bb9ad9dc516e960288a372e575f20bfab1ba3f03fa6706d6a1c26fe53328a79ff849cd6e815211452b5c7f5253ec3dbffb
7
+ data.tar.gz: 2bc1e394f9fef5e755ddc5c2fef79e6c42fb9fd3c18d4d21db7a2f992c32b82e1c44841d4fe4e29cceeade7739caa1ceb9190b8fe6e9e9d15599294c5e3d3175
@@ -19,11 +19,11 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # specify any dependencies here; for example:
22
- s.add_dependency(%q<activesupport>, ["~> 4.0.5"])
23
- s.add_dependency(%q<activerecord>, ["~> 4.0.5"])
22
+ s.add_dependency(%q<activesupport>, ["> 4.0", "< 4.2"])
23
+ s.add_dependency(%q<activerecord>, ["> 4.0", "< 4.2"])
24
24
  s.add_dependency(%q<yard>, [">= 0"])
25
25
 
26
- s.add_development_dependency "rspec", "~> 3.0"
26
+ s.add_development_dependency "rspec"
27
27
  s.add_development_dependency "rspec-its"
28
28
  s.add_development_dependency "rake"
29
29
  end
@@ -1,3 +1,3 @@
1
1
  module FlatMap # :nodoc:
2
- VERSION = "0.2.1" # :nodoc:
2
+ VERSION = "0.3.0" # :nodoc:
3
3
  end
@@ -11,13 +11,13 @@ describe FlatMap::Errors do
11
11
 
12
12
  it "preserved errors should appear on #empty? call exactly once" do
13
13
  errors.preserve :base, 'an error'
14
- errors.should_not be_empty
15
- errors[:base].should == ['an error']
14
+ expect(errors).not_to be_empty
15
+ expect(errors[:base]).to eq ['an error']
16
16
  expect{ errors.empty? }.not_to change{ errors[:base].length }
17
17
  end
18
18
 
19
19
  it "should add error to mapper with suffix" do
20
20
  errors.add(:attr, 'an error')
21
- errors[:attr_foo].should == ['an error']
21
+ expect(errors[:attr_foo]).to eq ['an error']
22
22
  end
23
23
  end
@@ -8,8 +8,8 @@ module FlatMap
8
8
  end
9
9
 
10
10
  describe 'Attribute Methods' do
11
- let(:target){ OpenStruct.new }
12
- let(:mapper){ AttributeMethodsSpec::SpecMapper.new(target) }
11
+ let(:target) { OpenStruct.new }
12
+ let(:mapper) { AttributeMethodsSpec::SpecMapper.new(target) }
13
13
 
14
14
  before do
15
15
  target.attr_a = 'a'
@@ -17,27 +17,27 @@ module FlatMap
17
17
  end
18
18
 
19
19
  it 'correctly responds to dynamic methods' do
20
- mapper.respond_to?(:attr_a=).should be true
21
- mapper.method(:attr_a=).should_not be nil
20
+ expect(mapper).to respond_to(:attr_a=)
21
+ expect(mapper.method(:attr_a=)).not_to be_nil
22
22
 
23
- mapper.respond_to?(:attr_b=).should be true
24
- mapper.method(:attr_b=).should_not be nil
23
+ expect(mapper).to respond_to(:attr_b=)
24
+ expect(mapper.method(:attr_b=)).not_to be_nil
25
25
  end
26
26
 
27
27
  it 'should be able to read values via method calls' do
28
- mapper.attr_a.should == 'a'
29
- mapper.attr_b.should == 'b'
28
+ expect(mapper.attr_a).to eq 'a'
29
+ expect(mapper.attr_b).to eq 'b'
30
30
  end
31
31
 
32
32
  it 'should be able to write values via method calls' do
33
33
  mapper.attr_a = 'A'
34
34
  mapper.attr_b = 'B'
35
- target.attr_a.should == 'A'
36
- target.attr_b.should == 'B'
35
+ expect(target.attr_a).to eq 'A'
36
+ expect(target.attr_b).to eq 'B'
37
37
  end
38
38
 
39
39
  it 'should still raise for unknown or private method calls' do
40
- expect{ mapper.undefined_method }.to raise_error(NoMethodError)
40
+ expect{ mapper.undefined_method }.to raise_error(NoMethodError)
41
41
  expect{ mapper.attribute_methods }.to raise_error(NoMethodError)
42
42
  end
43
43
  end
@@ -49,27 +49,27 @@ module FlatMap
49
49
  end
50
50
 
51
51
  it 'should call callbacks once' do
52
- mapper.should_receive(:set_a).once
52
+ expect(mapper).to receive(:set_a).once
53
53
  mapper.save
54
54
  end
55
55
 
56
56
  specify 'validation callbacks' do
57
57
  mapper.valid?
58
- mapper.attr_a.should be_nil
59
- mapper.attr_b.should == 'before validate'
60
- mapper.attr_c.should == 'mounted before validate'
58
+ expect(mapper.attr_a).to be_nil
59
+ expect(mapper.attr_b).to eq 'before validate'
60
+ expect(mapper.attr_c).to eq 'mounted before validate'
61
61
  end
62
62
 
63
63
  specify 'save callbacks' do
64
64
  mapper.save
65
- mapper.attr_a.should == 'before save'
65
+ expect(mapper.attr_a).to eq 'before save'
66
66
  end
67
67
 
68
68
  context 'extension trait and named traits' do
69
69
  it 'should process extension first' do
70
- mapper.extension.should_receive(:extension_set_b).once.and_call_original
70
+ expect(mapper.extension).to receive(:extension_set_b).once.and_call_original
71
71
  mapper.valid?
72
- mapper.attr_b.should == 'before validate'
72
+ expect(mapper.attr_b).to eq 'before validate'
73
73
  end
74
74
  end
75
75
  end
@@ -2,40 +2,40 @@ require 'spec_helper'
2
2
 
3
3
  module FlatMap
4
4
  describe OpenMapper::Factory do
5
- let(:trait_class){ Class.new(FlatMap::OpenMapper) }
6
- let(:mapper){ OpenMapper.build }
5
+ let(:trait_class) { Class.new(FlatMap::OpenMapper) }
6
+ let(:mapper) { OpenMapper.build }
7
7
 
8
- let(:mount_factory){ OpenMapper::Factory.new(:spec_mount, :traits => :used_traits) }
9
- let(:trait_factory){ OpenMapper::Factory.new(trait_class, :trait_name => :a_trait) }
10
- let(:open_factory){ OpenMapper::Factory.new(:some_mount, :open => true) }
8
+ let(:mount_factory) { OpenMapper::Factory.new(:spec_mount, :traits => :used_traits) }
9
+ let(:trait_factory) { OpenMapper::Factory.new(trait_class, :trait_name => :a_trait) }
10
+ let(:open_factory) { OpenMapper::Factory.new(:some_mount, :open => true) }
11
11
 
12
12
  context 'when used for a trait' do
13
13
  subject{ trait_factory }
14
14
 
15
- it{ should be_traited }
16
- its(:name){ should be_nil }
17
- its(:trait_name){ should == :a_trait }
18
- its(:mapper_class){ should == trait_class }
15
+ it{ is_expected.to be_traited }
16
+ its(:name) { is_expected.to be_nil }
17
+ its(:trait_name) { is_expected.to eq :a_trait }
18
+ its(:mapper_class) { is_expected.to eq trait_class }
19
19
  end
20
20
 
21
21
  context 'when used for a mounted mapper' do
22
22
  subject{ mount_factory }
23
23
 
24
- it{ should_not be_traited }
25
- its(:name){ should == :spec_mount }
26
- its(:trait_name){ should be_nil }
27
- its(:traits){ should == [:used_traits] }
24
+ it{ is_expected.not_to be_traited }
25
+ its(:name) { is_expected.to eq :spec_mount }
26
+ its(:trait_name) { is_expected.to be_nil }
27
+ its(:traits) { is_expected.to eq [:used_traits] }
28
28
  end
29
29
 
30
30
  context 'when used for an open mapper' do
31
31
  it "should have descendant of OpenMapper as mapper_class" do
32
- open_factory.mapper_class.should < OpenMapper
33
- open_factory.mapper_class.name.should == 'SomeMountMapper'
32
+ expect(open_factory.mapper_class.ancestors).to include(OpenMapper)
33
+ expect(open_factory.mapper_class.name).to eq 'SomeMountMapper'
34
34
  end
35
35
 
36
36
  it "should create and instance of OpenMapper with open struct as a target" do
37
37
  mounted = open_factory.create(mapper)
38
- mounted.target.should be_a(OpenStruct)
38
+ expect(mounted.target).to be_a(OpenStruct)
39
39
  end
40
40
  end
41
41
 
@@ -48,7 +48,7 @@ module FlatMap
48
48
  class OpenMapper::Factory::SpecMountMapper < FlatMap::OpenMapper; end
49
49
 
50
50
  it "should be able to fetch class name from name" do
51
- mount_factory.mapper_class.should == ::SpecMountMapper
51
+ expect(mount_factory.mapper_class.ancestors).to include(::SpecMountMapper)
52
52
  end
53
53
 
54
54
  it "should be able to fetch class from mapper_class" do
@@ -56,7 +56,8 @@ module FlatMap
56
56
  :spec_mount,
57
57
  :mapper_class => FlatMap::OpenMapper::Factory::SpecMountMapper
58
58
  )
59
- factory.mapper_class.should == ::FlatMap::OpenMapper::Factory::SpecMountMapper
59
+ expect(factory.mapper_class.ancestors).
60
+ to include(::FlatMap::OpenMapper::Factory::SpecMountMapper)
60
61
  end
61
62
 
62
63
  it "should use options if specified" do
@@ -64,38 +65,39 @@ module FlatMap
64
65
  :spec_mount,
65
66
  :mapper_class_name => 'FlatMap::OpenMapper::Factory::SpecMountMapper'
66
67
  )
67
- factory.mapper_class.should == ::FlatMap::OpenMapper::Factory::SpecMountMapper
68
+ expect(factory.mapper_class.ancestors).
69
+ to include(::FlatMap::OpenMapper::Factory::SpecMountMapper)
68
70
  end
69
71
  end
70
72
 
71
73
  describe '#fetch_target_from' do
72
74
  it "should return owner's target for traited factory" do
73
- trait_factory.fetch_target_from(mapper).should == target
75
+ expect(trait_factory.fetch_target_from(mapper)).to eq target
74
76
  end
75
77
 
76
78
  context 'explicit target' do
77
79
  it "should use explicitly specified if applicable" do
78
80
  factory = OpenMapper::Factory.new(:spec_mount, :target => other_target)
79
- factory.fetch_target_from(mapper).should == other_target
81
+ expect(factory.fetch_target_from(mapper)).to eq other_target
80
82
  end
81
83
 
82
84
  it "should call Proc and pass owner target to it if Proc is specified as :target" do
83
85
  factory = OpenMapper::Factory.new(:spec_mount, :target => lambda{ |obj| obj.foo })
84
- target.should_receive(:foo).and_return(other_target)
85
- factory.fetch_target_from(mapper).should == other_target
86
+ expect(target).to receive(:foo).and_return(other_target)
87
+ expect(factory.fetch_target_from(mapper)).to eq other_target
86
88
  end
87
89
 
88
90
  it "should call a method if Symbol is used" do
89
91
  factory = OpenMapper::Factory.new(:spec_mount, :target => :foo)
90
- mapper.should_receive(:foo).and_return(other_target)
91
- factory.fetch_target_from(mapper).should == other_target
92
+ expect(mapper).to receive(:foo).and_return(other_target)
93
+ expect(factory.fetch_target_from(mapper)).to eq other_target
92
94
  end
93
95
  end
94
96
 
95
97
  context 'target from association' do
96
98
  before do
97
- target.stub(:is_a?).and_call_original
98
- target.stub(:is_a?).with(ActiveRecord::Base).and_return(true)
99
+ allow(target).to receive(:is_a?).and_call_original
100
+ expect(target).to receive(:is_a?).with(ActiveRecord::Base).and_return(true)
99
101
  end
100
102
 
101
103
  let(:has_one_current_reflection) {
@@ -113,68 +115,68 @@ module FlatMap
113
115
 
114
116
  it "should refer to effective name for has_one_current association" do
115
117
  # Note: has_one_current is not part of Rails
116
- mount_factory.should_receive(:reflection_from_target).
118
+ expect(mount_factory).to receive(:reflection_from_target).
117
119
  with(target).
118
120
  and_return(has_one_current_reflection)
119
- target.should_receive(:effective_spec_mount).and_return(other_target)
120
- mount_factory.fetch_target_from(mapper).should == other_target
121
+ expect(target).to receive(:effective_spec_mount).and_return(other_target)
122
+ expect(mount_factory.fetch_target_from(mapper)).to eq other_target
121
123
  end
122
124
 
123
125
  it "should refer to existing association object if possible, " \
124
126
  "and build it if it is absent for :has_one" do
125
- mount_factory.should_receive(:reflection_from_target).
127
+ expect(mount_factory).to receive(:reflection_from_target).
126
128
  with(target).
127
129
  and_return(has_one_reflection)
128
- target.should_receive(:spec_mount).and_return(nil)
129
- target.should_receive(:build_spec_mount).and_return(other_target)
130
- mount_factory.fetch_target_from(mapper).should == other_target
130
+ expect(target).to receive(:spec_mount).and_return(nil)
131
+ expect(target).to receive(:build_spec_mount).and_return(other_target)
132
+ expect(mount_factory.fetch_target_from(mapper)).to eq other_target
131
133
  end
132
134
 
133
135
  it "should refer to existing association object if possible, " \
134
136
  "and build it if it is absent for :belongs_to" do
135
- mount_factory.should_receive(:reflection_from_target).
137
+ expect(mount_factory).to receive(:reflection_from_target).
136
138
  with(target).
137
139
  and_return(belongs_to_reflection)
138
- target.should_receive(:spec_mount).and_return(nil)
139
- target.should_receive(:build_spec_mount).and_return(other_target)
140
- mount_factory.fetch_target_from(mapper).should == other_target
140
+ expect(target).to receive(:spec_mount).and_return(nil)
141
+ expect(target).to receive(:build_spec_mount).and_return(other_target)
142
+ expect(mount_factory.fetch_target_from(mapper)).to eq other_target
141
143
  end
142
144
 
143
145
  it "should always build a new record for :has_many association" do
144
- mount_factory.should_receive(:reflection_from_target).
146
+ expect(mount_factory).to receive(:reflection_from_target).
145
147
  with(target).
146
148
  and_return(has_many_reflection)
147
- target.should_receive(:association).with(:spec_mounts)
148
- target.stub_chain(:association, :build).and_return(other_target)
149
- mount_factory.fetch_target_from(mapper).should == other_target
149
+ expect(target).to receive(:association).with(:spec_mounts)
150
+ allow(target).to receive_message_chain(:association, :build).and_return(other_target)
151
+ expect(mount_factory.fetch_target_from(mapper)).to eq other_target
150
152
  end
151
153
 
152
154
  describe 'reflection_from_target' do
153
- before{ target.stub(:is_a?).with(ActiveRecord::Base).and_return(true) }
155
+ before{ allow(target).to receive(:is_a?).with(ActiveRecord::Base).and_return(true) }
154
156
 
155
157
  it 'should first refer to singular association' do
156
- target.stub_chain(:class, :reflect_on_association).
158
+ allow(target).to receive_message_chain(:class, :reflect_on_association).
157
159
  with(:spec_mount).
158
160
  and_return(has_one_reflection)
159
- mount_factory.reflection_from_target(target).should == has_one_reflection
161
+ expect(mount_factory.reflection_from_target(target)).to eq has_one_reflection
160
162
  end
161
163
 
162
164
  it 'should use collection association if singular does not exist' do
163
- target.stub_chain(:class, :reflect_on_association).
165
+ allow(target).to receive_message_chain(:class, :reflect_on_association).
164
166
  with(:spec_mount).
165
167
  and_return(nil)
166
- target.stub_chain(:class, :reflect_on_association).
168
+ allow(target).to receive_message_chain(:class, :reflect_on_association).
167
169
  with(:spec_mounts).
168
170
  and_return(has_many_reflection)
169
- mount_factory.reflection_from_target(target).should == has_many_reflection
171
+ expect(mount_factory.reflection_from_target(target)).to eq has_many_reflection
170
172
  end
171
173
  end
172
174
  end
173
175
 
174
176
  context 'target from name' do
175
177
  it 'should simply send method to owner target' do
176
- target.should_receive(:spec_mount).and_return(other_target)
177
- mount_factory.fetch_target_from(mapper).should == other_target
178
+ expect(target).to receive(:spec_mount).and_return(other_target)
179
+ expect(mount_factory.fetch_target_from(mapper)).to eq other_target
178
180
  end
179
181
  end
180
182
  end
@@ -182,7 +184,7 @@ module FlatMap
182
184
  describe '#create' do
183
185
  specify 'traited factory should create an owned mapper' do
184
186
  new_one = trait_factory.create(mapper)
185
- new_one.owner.should == mapper
187
+ expect(new_one.owner).to eq mapper
186
188
  end
187
189
 
188
190
  context 'mounted mapper' do
@@ -190,12 +192,12 @@ module FlatMap
190
192
  let(:factory){ mount_factory }
191
193
 
192
194
  before do
193
- factory.stub(:mapper_class).and_return(mount_class)
194
- factory.stub(:fetch_target_from).and_return(other_target)
195
+ allow(factory).to receive(:mapper_class ).and_return(mount_class)
196
+ allow(factory).to receive(:fetch_target_from).and_return(other_target)
195
197
  end
196
198
 
197
199
  it 'should combine traits' do
198
- mount_class.should_receive(:new).
200
+ expect(mount_class).to receive(:new).
199
201
  with(other_target, :used_traits, :another_trait).
200
202
  and_call_original
201
203
  factory.create(mapper, :another_trait)
@@ -203,10 +205,10 @@ module FlatMap
203
205
 
204
206
  it 'should properly set properties' do
205
207
  new_one = factory.create(mapper)
206
- new_one.host .should == mapper
207
- new_one.name .should == :spec_mount
208
- new_one.save_order.should == :after
209
- new_one.suffix.should be_nil
208
+ expect(new_one.host ).to eq mapper
209
+ expect(new_one.name ).to eq :spec_mount
210
+ expect(new_one.save_order).to eq :after
211
+ expect(new_one.suffix ).to be_nil
210
212
  end
211
213
 
212
214
  context 'when suffix is defined' do
@@ -214,8 +216,8 @@ module FlatMap
214
216
 
215
217
  it "should adjust properties with suffix" do
216
218
  new_one = factory.create(mapper)
217
- new_one.name .should == :spec_mount_foo
218
- new_one.suffix.should == :foo
219
+ expect(new_one.name ).to eq :spec_mount_foo
220
+ expect(new_one.suffix).to eq :foo
219
221
  end
220
222
  end
221
223
 
@@ -224,7 +226,7 @@ module FlatMap
224
226
  let(:factory){ OpenMapper::Factory.new(:spec_mount, &extension) }
225
227
 
226
228
  it "should pass it to mapper initialization" do
227
- mount_class.should_receive(:new).
229
+ expect(mount_class).to receive(:new).
228
230
  with(other_target, &extension).
229
231
  and_call_original
230
232
  new_one = factory.create(mapper)
@@ -233,20 +235,20 @@ module FlatMap
233
235
 
234
236
  describe 'save order' do
235
237
  before do
236
- mapper.stub(:is_a?).and_call_original
237
- mapper.stub(:is_a?).with(ModelMapper).and_return(true)
238
+ allow(mapper).to receive(:is_a?).and_call_original
239
+ allow(mapper).to receive(:is_a?).with(ModelMapper).and_return(true)
238
240
  end
239
241
 
240
242
  it 'should be :before for belongs_to association' do
241
- factory.stub(:reflection_from_target).
243
+ expect(factory).to receive(:reflection_from_target).
242
244
  and_return(double('reflection', :macro => :belongs_to))
243
- factory.fetch_save_order(mapper).should == :before
245
+ expect(factory.fetch_save_order(mapper)).to eq :before
244
246
  end
245
247
 
246
248
  it 'should be :after for other cases' do
247
- factory.stub(:reflection_from_target).
249
+ expect(factory).to receive(:reflection_from_target).
248
250
  and_return(double('reflection', :macro => :has_one))
249
- factory.fetch_save_order(mapper).should == :after
251
+ expect(factory.fetch_save_order(mapper)).to eq :after
250
252
  end
251
253
 
252
254
  context 'when explicitly set' do
@@ -254,7 +256,7 @@ module FlatMap
254
256
 
255
257
  it 'should fetch from options, if possible' do
256
258
  new_one = factory.create(mapper)
257
- new_one.save_order.should == :before
259
+ expect(new_one.save_order).to eq :before
258
260
  end
259
261
  end
260
262
  end
@@ -273,11 +275,11 @@ module FlatMap
273
275
  let(:factory_for_b){ mapper_class.mountings.first.mapper_class.mountings.first }
274
276
 
275
277
  it "should be required for nested trait" do
276
- factory_for_b.required_for_any_trait?([:trait_c]).should be true
278
+ expect(factory_for_b.required_for_any_trait?([:trait_c])).to be true
277
279
  end
278
280
 
279
281
  it "should not be required for top trait" do
280
- factory_for_b.required_for_any_trait?([:trait_a]).should be false
282
+ expect(factory_for_b.required_for_any_trait?([:trait_a])).to be false
281
283
  end
282
284
  end
283
285
  end