cot 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzRhMGE4M2I0NmZlYjUyMTRkMjdlMzQ2MzNkNjUzNGM0Y2M5MjI1MA==
4
+ MmQ0MWNjZWVjMTJkNDI3ZGJmNWFhNTFjZTkxZTc4NWE2MDRjMjRmNw==
5
5
  data.tar.gz: !binary |-
6
- OWFhMTM2MmI3NjQ1ZTE3OTFhMDMwZTA2YzY3NDVhNDJkN2QwOWYyZg==
6
+ MzgzYmFlYjM3NjEzNzYxM2UxYTI1ZmRmYzk0NzIzZmVkMjEwZDAyYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWM5ZTA2OTJjMWFmY2IxOTA5MTE1NmNlNGY4OTdmM2U5Y2Q0NmJhYzdiNmEw
10
- OWFjNDAwNGZjZDViMDNhZTk0YjY5N2IxMjVkMThlMGEwYmNmMzRlYTU1MzUz
11
- YTI2MTQ0ODNkMjA4MzY2OGZmMGYxZGQ2ZDIxYzVmYjQxOWVmMmU=
9
+ NjA1OWJmYWFmYzQ2OWNhNzdjZWUxMThhMmRlMDcxMWQ1OWI2MTYyOTY3ZjZi
10
+ Njc1ZTc5ZWQ2OWFlYzc5NjhjZDEwOGNmM2FkM2I2NmU3NjBlYTBlMGViOGEz
11
+ MWEyMGQwZWZhZmVjMGJhY2NkMDg0YTM4OGE2NDY1ZmIwMTZhNWY=
12
12
  data.tar.gz: !binary |-
13
- ZWQ2MTJlNzFiMzNmNTkyMmI3NDRjZDg2NmEzMTY0M2RlYWZiMGYwZjBkYmE5
14
- NDgwMTYzMDI0NTBmYmY3OGUwMzE5Nzc2Y2Q4OTc1NGIxM2Q3ODZkNDg2YmRl
15
- ODE0ZTBlNjk3NGVhOTQ4ZWZjMzY2ZGZlZGQzNDNhM2NmOGU0ZmE=
13
+ NjA1ZTYxYzIxOTg2ZmQwOTM0ZTVlZDQ5YzFjMTkxZWMxODk2YTdiZmQ5ZmIx
14
+ N2E2NGU2ZmUxNzMwMjFjMTA3NDEyYjc5N2Y2ODVkNzlmMWQwMjgzYWRlZjMy
15
+ MjA3ZjNmNDY0Y2YyN2MzYzA3MzkwNzQ4M2ViMmJjYzA4OTE0YjM=
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.1.5
4
- #- 2.0.0
4
+ - 2.0.0
5
5
  - 2.2.0
6
6
  script:
7
7
  - bundle exec rake
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cot (0.5.2)
4
+ cot (0.5.3)
5
5
  activemodel
6
6
 
7
7
  GEM
data/Rakefile CHANGED
@@ -17,6 +17,7 @@ task test: :spec
17
17
  require 'mutant'
18
18
  desc 'Run mutation tests using mutant'
19
19
  task :mutant do
20
+ ENV['SKIP_COVERAGE'] = 'true'
20
21
  result = Mutant::CLI.run(%w( -Ilib -rcot --use rspec Cot* ))
21
22
  fail unless result == Mutant::CLI::EXIT_SUCCESS
22
23
  end
@@ -11,6 +11,9 @@ module Cot
11
11
  def initialize(*params)
12
12
  parse_params(params)
13
13
 
14
+ if self.class.klass.nil?
15
+ fail 'Collected class not set, please either pass a class to initialize or call collected_class'
16
+ end
14
17
  # If you pass in different types of things here we can't be friends
15
18
  initialize_objects(@objects) unless @objects.first.instance_of? self.class.klass
16
19
 
@@ -1,3 +1,3 @@
1
1
  module Cot
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
@@ -4,8 +4,14 @@ class FakeDouble < Cot::Frame
4
4
  property :foo
5
5
  property :fooy
6
6
  end
7
+ class ExampleCollection < Cot::Collection
8
+ end
7
9
 
8
10
  describe Cot::Collection do
11
+ after :each do
12
+ ExampleCollection.klass = nil
13
+ end
14
+
9
15
  let(:obj1) { FakeDouble.new id: 1, foo: :bar }
10
16
  let(:obj2) { FakeDouble.new id: 2, foo: :bar }
11
17
  subject(:collection) { Cot::Collection.new FakeDouble, [obj1, obj2] }
@@ -73,29 +79,29 @@ describe Cot::Collection do
73
79
  context 'when passing a class' do
74
80
  context 'with options' do
75
81
  it 'takes an optional sub_key option to pull the object out of the payload' do
76
- coll = Cot::Collection.new FakeDouble,
77
- [{ inner: { fooy: :bar } }, { inner: { asdf: :fdas } }],
78
- sub_key: :inner
82
+ coll = ExampleCollection.new FakeDouble,
83
+ [{ inner: { fooy: :bar } }, { inner: { asdf: :fdas } }],
84
+ sub_key: :inner
79
85
  expect(coll.first).to be_kind_of FakeDouble
80
86
  expect(coll.first.fooy).to eq :bar
81
87
  end
82
88
 
83
89
  it 'takes options as strings and symbols' do
84
- coll = Cot::Collection.new FakeDouble,
85
- [{ inner: { fooy: :bar } }, { inner: { asdf: :fdas } }],
86
- 'sub_key' => :inner
90
+ coll = ExampleCollection.new FakeDouble,
91
+ [{ inner: { fooy: :bar } }, { inner: { asdf: :fdas } }],
92
+ 'sub_key' => :inner
87
93
  expect(coll.first).to be_kind_of FakeDouble
88
94
  expect(coll.first.fooy).to eq :bar
89
95
  end
90
96
 
91
97
  it 'takes an optional default_attributes option to add set attributes in every object.' do
92
- coll = Cot::Collection.new FakeDouble, [{ fooy: :bar }, { asdf: :fdas }], default_attributes: { foo: :baz }
98
+ coll = ExampleCollection.new FakeDouble, [{ fooy: :bar }, { asdf: :fdas }], default_attributes: { foo: :baz }
93
99
  expect(coll).to all be_kind_of FakeDouble
94
100
  expect(coll.map(&:foo).uniq).to eq [:baz]
95
101
  end
96
102
 
97
103
  it 'supports a legacy optional sub_key parameter to pull the object out of the payload' do
98
- coll = Cot::Collection.new FakeDouble, [{ inner: { fooy: :bar } }, { inner: { asdf: :fdas } }], :inner
104
+ coll = ExampleCollection.new FakeDouble, [{ inner: { fooy: :bar } }, { inner: { asdf: :fdas } }], :inner
99
105
  expect(coll.first).to be_kind_of FakeDouble
100
106
  expect(coll.first.fooy).to eq :bar
101
107
  end
@@ -103,22 +109,22 @@ describe Cot::Collection do
103
109
 
104
110
  context 'without options' do
105
111
  it 'does not process the objects if they are already the correct class' do
106
- coll = Cot::Collection.new [FakeDouble.new(fooy: :bar), FakeDouble.new(asdf: :fdas)]
112
+ coll = ExampleCollection.new FakeDouble, [FakeDouble.new(fooy: :bar), FakeDouble.new(asdf: :fdas)]
107
113
  expect(coll.first).to be_kind_of FakeDouble
108
114
  end
109
115
 
110
116
  it 'does not set the subkey if none is provided' do
111
- coll = Cot::Collection.new [FakeDouble.new(fooy: :bar), FakeDouble.new(asdf: :fdas)]
117
+ coll = ExampleCollection.new FakeDouble, [FakeDouble.new(fooy: :bar), FakeDouble.new(asdf: :fdas)]
112
118
  expect(coll.instance_variable_get :@options).to_not have_key :sub_key
113
119
  end
114
120
 
115
121
  it 'can accept empty hashes' do
116
- coll = Cot::Collection.new FakeDouble, [{}]
122
+ coll = ExampleCollection.new FakeDouble, [{}]
117
123
  expect(coll.first).to be_kind_of FakeDouble
118
124
  end
119
125
 
120
126
  it 'creates new instances of the passed klass if the objects are not already the class' do
121
- coll = Cot::Collection.new FakeDouble, [{ fooy: :bar }, { asdf: :fdas }]
127
+ coll = ExampleCollection.new FakeDouble, [{ fooy: :bar }, { asdf: :fdas }]
122
128
  expect(coll.first).to be_kind_of FakeDouble
123
129
  end
124
130
  end
@@ -169,28 +175,34 @@ describe Cot::Collection do
169
175
 
170
176
  context 'without options' do
171
177
  it 'does not process the objects if they are already the correct class' do
172
- coll = Cot::Collection.new [FakeDouble.new(fooy: :bar), FakeDouble.new(asdf: :fdas)]
178
+ coll = MyCollection.new [FakeDouble.new(fooy: :bar), FakeDouble.new(asdf: :fdas)]
173
179
  expect(coll.first).to be_kind_of FakeDouble
174
180
  end
175
181
 
176
182
  it 'creates new instances of the passed klass if the objects are not already the class' do
177
- coll = Cot::Collection.new [{ fooy: :bar }, { asdf: :fdas }]
183
+ coll = MyCollection.new [{ fooy: :bar }, { asdf: :fdas }]
178
184
  expect(coll.first).to be_kind_of FakeDouble
179
185
  end
180
186
  end
181
187
  end
188
+
189
+ it 'fails if no klass is set' do
190
+ class BadCollection < Cot::Collection; end
191
+ error = 'Collected class not set, please either pass a class to initialize or call collected_class'
192
+ expect { BadCollection.new }.to raise_error error
193
+ end
182
194
  end
183
195
 
184
196
  context 'update members' do
185
197
  it 'updates members' do
186
- coll = Cot::Collection.new FakeDouble, [{ fooy: :bar }]
198
+ coll = ExampleCollection.new FakeDouble, [{ fooy: :bar }]
187
199
  expect(coll.length).to eq 1
188
200
  coll.update_members [{ id: 123, foo: :bar }]
189
201
  expect(coll.first.id).to eq 123
190
202
  end
191
203
 
192
204
  it 'removes members that are not in the payload' do
193
- coll = Cot::Collection.new FakeDouble, [{ fooy: :bar }, { asdf: :fdas }]
205
+ coll = ExampleCollection.new FakeDouble, [{ fooy: :bar }, { asdf: :fdas }]
194
206
  expect(coll.length).to eq 2
195
207
  coll.update_members [{ id: 123, foo: :bar }]
196
208
  expect(coll.first.id).to eq 123
@@ -200,13 +212,13 @@ describe Cot::Collection do
200
212
 
201
213
  context 'changed?' do
202
214
  it 'returns true if one of the objects has changed' do
203
- coll = Cot::Collection.new FakeDouble, [{ fooy: :bar }]
215
+ coll = ExampleCollection.new FakeDouble, [{ fooy: :bar }]
204
216
  coll.first.fooy = 'baz'
205
217
  expect(coll.changed?).to be true
206
218
  end
207
219
 
208
220
  it 'return false if none of the objects have changed' do
209
- coll = Cot::Collection.new FakeDouble, [{ fooy: :bar }]
221
+ coll = ExampleCollection.new FakeDouble, [{ fooy: :bar }]
210
222
  expect(coll.changed?).to be false
211
223
  end
212
224
  end
@@ -2,8 +2,7 @@ require 'simplecov'
2
2
 
3
3
  ENV['RAILS_ENV'] ||= 'test'
4
4
 
5
- require 'simplecov'
6
- SimpleCov.start
5
+ SimpleCov.start unless ENV['SKIP_COVERAGE']
7
6
 
8
7
  require 'cot'
9
8
  require 'rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Henrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-01 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel