opium 1.0.3 → 1.1.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/generators/opium/model_generator.rb +2 -0
- data/lib/opium/config.rb +1 -1
- data/lib/opium/extensions/symbol.rb +13 -0
- data/lib/opium/extensions.rb +1 -0
- data/lib/opium/file.rb +95 -0
- data/lib/opium/model/attributable.rb +5 -5
- data/lib/opium/model/batchable/batch.rb +43 -0
- data/lib/opium/model/batchable/operation.rb +33 -0
- data/lib/opium/model/batchable.rb +10 -0
- data/lib/opium/model/connectable.rb +7 -0
- data/lib/opium/model/fieldable.rb +1 -1
- data/lib/opium/model/persistable.rb +7 -4
- data/lib/opium/model/queryable.rb +2 -2
- data/lib/opium/model.rb +3 -0
- data/lib/opium/version.rb +1 -1
- data/lib/opium.rb +10 -9
- data/opium.gemspec +2 -0
- data/spec/opium/extensions/symbol_spec.rb +54 -0
- data/spec/opium/file_spec.rb +274 -0
- data/spec/opium/model/attributable_spec.rb +30 -16
- data/spec/opium/model/batchable/batch_spec.rb +145 -0
- data/spec/opium/model/batchable/operation_spec.rb +73 -0
- data/spec/opium/model/batchable_spec.rb +5 -0
- data/spec/opium/model/connectable_spec.rb +27 -0
- data/spec/opium/model/fieldable_spec.rb +35 -0
- data/spec/opium/model/persistable_spec.rb +35 -34
- data/spec/opium/model/queryable_spec.rb +35 -25
- data/spec/opium/model_spec.rb +1 -0
- data/spec/opium_spec.rb +1 -1
- metadata +33 -3
@@ -3,61 +3,61 @@ require 'spec_helper.rb'
|
|
3
3
|
describe Opium::Model::Persistable do
|
4
4
|
let( :model ) { Class.new { include Opium::Model::Persistable } }
|
5
5
|
|
6
|
-
|
6
|
+
context 'within a model' do
|
7
7
|
subject { model }
|
8
8
|
|
9
|
-
it {
|
10
|
-
it {
|
11
|
-
it {
|
12
|
-
it {
|
13
|
-
it {
|
14
|
-
it {
|
9
|
+
it { is_expected.to respond_to( :destroy_all ).with(1).argument }
|
10
|
+
it { is_expected.to respond_to( :delete_all ).with(1).argument }
|
11
|
+
it { is_expected.to respond_to( :create, :create! ).with(1).argument }
|
12
|
+
it { is_expected.to respond_to( :add_header_to ).with(4).arguments }
|
13
|
+
it { is_expected.to respond_to( :added_headers ) }
|
14
|
+
it { is_expected.to respond_to( :get_header_for ).with(2).arguments }
|
15
15
|
|
16
|
-
describe '
|
16
|
+
describe '.added_headers' do
|
17
17
|
it { subject.added_headers.should be_a( Hash ) }
|
18
18
|
end
|
19
19
|
|
20
|
-
describe '
|
20
|
+
describe '.add_header_to' do
|
21
21
|
after { subject.added_headers.clear }
|
22
22
|
|
23
23
|
it { expect { subject.add_header_to :put, :x_header, 42 }.to_not raise_exception }
|
24
24
|
it { subject.add_header_to(:delete, :x_header, 37, only: :delete).should be_nil }
|
25
25
|
|
26
|
-
it '
|
26
|
+
it 'adds header information to :added_headers' do
|
27
27
|
subject.add_header_to( :put, :x_header, 42, except: :update )
|
28
28
|
subject.added_headers.should have_key(:put)
|
29
29
|
subject.added_headers[:put].should include( :header, :value, :options )
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe '
|
33
|
+
describe '.get_header_for' do
|
34
34
|
after { subject.added_headers.clear }
|
35
35
|
|
36
|
-
it '
|
36
|
+
it 'returns an empty hash if a method has no added headers' do
|
37
37
|
subject.get_header_for( :put, :update ).should == {}
|
38
38
|
end
|
39
39
|
|
40
|
-
it '
|
40
|
+
it 'returns an empty hash if a context is not within the only list for a method' do
|
41
41
|
subject.add_header_to( :put, :x_header, 42, only: [:foo, :bar] )
|
42
42
|
subject.get_header_for( :put, :baz ).should == {}
|
43
43
|
end
|
44
44
|
|
45
|
-
it '
|
45
|
+
it 'returns an empty hash if a context is within the except list for a method' do
|
46
46
|
subject.add_header_to( :put, :x_header, 42, except: [:foo, :bar] )
|
47
47
|
subject.get_header_for( :put, :foo ).should == {}
|
48
48
|
end
|
49
49
|
|
50
|
-
it '
|
50
|
+
it 'returns a headers hash if context-free' do
|
51
51
|
subject.add_header_to( :put, :x_header, 42 )
|
52
52
|
subject.get_header_for( :put, :update ).should == { headers: { x_header: 42 } }
|
53
53
|
end
|
54
54
|
|
55
|
-
it '
|
55
|
+
it 'returns a headers hash if a context is within the only list for a method' do
|
56
56
|
subject.add_header_to( :put, :x_header, 42, only: :update )
|
57
57
|
subject.get_header_for( :put, :update ).should == { headers: { x_header: 42 } }
|
58
58
|
end
|
59
59
|
|
60
|
-
it '
|
60
|
+
it 'returns a headers hash if a context is not within the except list for a method' do
|
61
61
|
subject.add_header_to( :put, :x_header, 42, except: :foo )
|
62
62
|
subject.get_header_for( :put, :update ).should == { headers: { x_header: 42 } }
|
63
63
|
end
|
@@ -67,17 +67,18 @@ describe Opium::Model::Persistable do
|
|
67
67
|
describe 'instance' do
|
68
68
|
subject { model.new }
|
69
69
|
|
70
|
-
it {
|
71
|
-
it {
|
72
|
-
it {
|
73
|
-
it {
|
74
|
-
it {
|
75
|
-
it {
|
76
|
-
it {
|
77
|
-
it {
|
70
|
+
it { is_expected.to respond_to( :save ).with(1).argument }
|
71
|
+
it { is_expected.to respond_to( :save! ).with(0).arguments }
|
72
|
+
it { is_expected.to respond_to( :update_attributes, :update_attributes! ).with(1).argument }
|
73
|
+
it { is_expected.to respond_to( :update, :update! ).with(1).argument }
|
74
|
+
it { is_expected.to respond_to( :touch ) }
|
75
|
+
it { is_expected.to respond_to( :destroy ) }
|
76
|
+
it { is_expected.to respond_to( :delete ) }
|
77
|
+
it { is_expected.to respond_to( :new_record?, :persisted? ) }
|
78
|
+
it { is_expected.to respond_to( :pointer, :to_parse ) }
|
78
79
|
end
|
79
80
|
|
80
|
-
|
81
|
+
context 'within a model' do
|
81
82
|
before do
|
82
83
|
stub_const( 'Game', Class.new do
|
83
84
|
include Opium::Model
|
@@ -93,7 +94,7 @@ describe Opium::Model::Persistable do
|
|
93
94
|
Opium::Model::Criteria.models.clear
|
94
95
|
end
|
95
96
|
|
96
|
-
describe '
|
97
|
+
describe '#new_record?' do
|
97
98
|
subject { Game.new }
|
98
99
|
|
99
100
|
it 'should be true in a model without an id' do
|
@@ -244,12 +245,12 @@ describe Opium::Model::Persistable do
|
|
244
245
|
it { expect { subject.save! }.to raise_exception }
|
245
246
|
end
|
246
247
|
|
247
|
-
|
248
|
+
context 'when saving a model with validates: false' do
|
248
249
|
subject { Game.new( title: 'Skyrim' ) }
|
249
|
-
|
250
|
-
it '
|
250
|
+
|
251
|
+
it 'does not receive :valid?, but does receive :_create' do
|
251
252
|
subject.should_not receive(:valid?)
|
252
|
-
subject.should receive(:
|
253
|
+
subject.should receive(:_create)
|
253
254
|
subject.save( validates: false )
|
254
255
|
end
|
255
256
|
end
|
@@ -356,11 +357,11 @@ describe Opium::Model::Persistable do
|
|
356
357
|
end
|
357
358
|
end
|
358
359
|
|
359
|
-
describe '
|
360
|
+
describe '#to_parse' do
|
360
361
|
subject { Game.new( id: 'abcd1234' ) }
|
361
362
|
|
362
|
-
it '
|
363
|
-
subject.to_parse.
|
363
|
+
it 'is a pointer hash' do
|
364
|
+
expect( subject.to_parse ).to eq subject.pointer.to_parse
|
364
365
|
end
|
365
366
|
end
|
366
367
|
end
|
@@ -3,28 +3,28 @@ require 'spec_helper.rb'
|
|
3
3
|
describe Opium::Model::Queryable do
|
4
4
|
let( :model ) { Class.new { include Opium::Model::Queryable } }
|
5
5
|
|
6
|
-
|
6
|
+
context 'when included in a class' do
|
7
7
|
subject { model }
|
8
8
|
|
9
|
-
it {
|
10
|
-
it {
|
11
|
-
it {
|
12
|
-
it {
|
13
|
-
it {
|
14
|
-
it {
|
15
|
-
it {
|
16
|
-
it {
|
17
|
-
it {
|
18
|
-
it {
|
19
|
-
it {
|
20
|
-
it {
|
21
|
-
it {
|
22
|
-
it {
|
23
|
-
it {
|
24
|
-
it {
|
9
|
+
it { is_expected.to respond_to( :all, :all_in ).with(1).argument }
|
10
|
+
it { is_expected.to respond_to( :and ).with(1).argument }
|
11
|
+
it { is_expected.to respond_to( :between ).with(1).argument }
|
12
|
+
it { is_expected.to respond_to( :exists ).with(1).argument }
|
13
|
+
it { is_expected.to respond_to( :gt, :gte ).with(1).argument }
|
14
|
+
it { is_expected.to respond_to( :lt, :lte ).with(1).argument }
|
15
|
+
it { is_expected.to respond_to( :in, :any_in, :nin ).with(1).argument }
|
16
|
+
it { is_expected.to respond_to( :ne ).with(1).argument }
|
17
|
+
it { is_expected.to respond_to( :or ).with(1).argument }
|
18
|
+
it { is_expected.to respond_to( :select, :dont_select ).with(1).argument }
|
19
|
+
it { is_expected.to respond_to( :keys, :pluck ).with(1).argument }
|
20
|
+
it { is_expected.to respond_to( :where ).with(1).argument }
|
21
|
+
it { is_expected.to respond_to( :order ).with(1).argument }
|
22
|
+
it { is_expected.to respond_to( :limit, :skip ).with(1).argument }
|
23
|
+
it { is_expected.to respond_to( :cache, :uncache, :cached? ) }
|
24
|
+
it { is_expected.to respond_to( :count, :total_count ) }
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
context 'within a model' do
|
28
28
|
before do
|
29
29
|
stub_const( 'Game', Class.new do
|
30
30
|
include Opium::Model
|
@@ -43,29 +43,29 @@ describe Opium::Model::Queryable do
|
|
43
43
|
|
44
44
|
subject { Game }
|
45
45
|
|
46
|
-
describe '
|
47
|
-
it '
|
46
|
+
describe '.where' do
|
47
|
+
it 'returns a criteria' do
|
48
48
|
subject.where( price: { '$lte' => 5 } ).should be_a( Opium::Model::Criteria )
|
49
49
|
end
|
50
50
|
|
51
|
-
it '
|
51
|
+
it 'sets the "where" constraint to the provided value' do
|
52
52
|
subject.where( price: { '$lte' => 5 } ).tap do |criteria|
|
53
53
|
criteria.constraints.should have_key( 'where' )
|
54
54
|
criteria.constraints['where'].should =~ { 'price' => { '$lte' => 5 } }
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
it '
|
58
|
+
it 'deep merges the "where" constraint on successive calls' do
|
59
59
|
subject.where( price: { '$lte' => 5 } ).where( price: { '$gte' => 1 } ).tap do |criteria|
|
60
60
|
criteria.constraints['where'].should =~ { 'price' => { '$lte' => 5, '$gte' => 1 } }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
it '
|
64
|
+
it 'ensures that specified fields exist on the model' do
|
65
65
|
expect { subject.where( does_not_exist: true ) }.to raise_exception
|
66
66
|
end
|
67
67
|
|
68
|
-
it '
|
68
|
+
it 'maps ruby names to parse names and ruby values to parse values' do
|
69
69
|
time = Time.now - 1000
|
70
70
|
subject.where( created_at: { '$gte' => time } ).tap do |criteria|
|
71
71
|
criteria.constraints['where'].should =~ { 'createdAt' => { '$gte' => time.to_parse } }
|
@@ -74,7 +74,7 @@ describe Opium::Model::Queryable do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
shared_examples_for 'a chainable criteria clause' do |method|
|
77
|
-
describe "
|
77
|
+
describe ".#{method}" do
|
78
78
|
it 'should return a criteria' do
|
79
79
|
subject.send( method, price: 5, title: 'Skyrim' ).should be_a( Opium::Model::Criteria )
|
80
80
|
end
|
@@ -124,6 +124,16 @@ describe Opium::Model::Queryable do
|
|
124
124
|
it_should_behave_like 'an aliased method', :and, :where
|
125
125
|
it_should_behave_like 'an aliased method', :all_in, :all
|
126
126
|
it_should_behave_like 'an aliased method', :any_in, :in
|
127
|
+
|
128
|
+
describe '.all' do
|
129
|
+
context 'when no parameter is given' do
|
130
|
+
let(:result) { subject.all }
|
131
|
+
|
132
|
+
it { expect { result }.to_not raise_exception }
|
133
|
+
it { expect( result ).to be_a Opium::Model::Criteria }
|
134
|
+
it { expect( result ).to eq subject.criteria }
|
135
|
+
end
|
136
|
+
end
|
127
137
|
|
128
138
|
describe ':exists' do
|
129
139
|
it 'should return a criteria' do
|
data/spec/opium/model_spec.rb
CHANGED
@@ -23,6 +23,7 @@ describe Opium::Model do
|
|
23
23
|
it { is_expected.to be <= Opium::Model::Scopable }
|
24
24
|
it { is_expected.to be <= Opium::Model::Findable }
|
25
25
|
it { is_expected.to be <= Opium::Model::Inheritable }
|
26
|
+
it { is_expected.to be <= Opium::Model::Batchable }
|
26
27
|
|
27
28
|
describe '#inspect' do
|
28
29
|
context 'within a blank model' do
|
data/spec/opium_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Bowers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0.9'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: mimemagic
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0.3'
|
230
|
+
type: :runtime
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0.3'
|
223
237
|
description: Provides an intuitive, Mongoid-inspired mapping layer between your application's
|
224
238
|
object space and Parse.
|
225
239
|
email:
|
@@ -231,6 +245,7 @@ files:
|
|
231
245
|
- ".coveralls.yml"
|
232
246
|
- ".gitignore"
|
233
247
|
- ".travis.yml"
|
248
|
+
- CHANGELOG.md
|
234
249
|
- Gemfile
|
235
250
|
- Guardfile
|
236
251
|
- LICENSE.txt
|
@@ -258,10 +273,15 @@ files:
|
|
258
273
|
- lib/opium/extensions/pointer.rb
|
259
274
|
- lib/opium/extensions/regexp.rb
|
260
275
|
- lib/opium/extensions/string.rb
|
276
|
+
- lib/opium/extensions/symbol.rb
|
261
277
|
- lib/opium/extensions/time.rb
|
262
278
|
- lib/opium/extensions/true_class.rb
|
279
|
+
- lib/opium/file.rb
|
263
280
|
- lib/opium/model.rb
|
264
281
|
- lib/opium/model/attributable.rb
|
282
|
+
- lib/opium/model/batchable.rb
|
283
|
+
- lib/opium/model/batchable/batch.rb
|
284
|
+
- lib/opium/model/batchable/operation.rb
|
265
285
|
- lib/opium/model/callbacks.rb
|
266
286
|
- lib/opium/model/connectable.rb
|
267
287
|
- lib/opium/model/criteria.rb
|
@@ -295,8 +315,13 @@ files:
|
|
295
315
|
- spec/opium/extensions/pointer_spec.rb
|
296
316
|
- spec/opium/extensions/regexp_spec.rb
|
297
317
|
- spec/opium/extensions/string_spec.rb
|
318
|
+
- spec/opium/extensions/symbol_spec.rb
|
298
319
|
- spec/opium/extensions/time_spec.rb
|
320
|
+
- spec/opium/file_spec.rb
|
299
321
|
- spec/opium/model/attributable_spec.rb
|
322
|
+
- spec/opium/model/batchable/batch_spec.rb
|
323
|
+
- spec/opium/model/batchable/operation_spec.rb
|
324
|
+
- spec/opium/model/batchable_spec.rb
|
300
325
|
- spec/opium/model/callbacks_spec.rb
|
301
326
|
- spec/opium/model/connectable_spec.rb
|
302
327
|
- spec/opium/model/criteria_spec.rb
|
@@ -327,7 +352,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
327
352
|
requirements:
|
328
353
|
- - ">="
|
329
354
|
- !ruby/object:Gem::Version
|
330
|
-
version:
|
355
|
+
version: 1.9.3
|
331
356
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
332
357
|
requirements:
|
333
358
|
- - ">="
|
@@ -354,8 +379,13 @@ test_files:
|
|
354
379
|
- spec/opium/extensions/pointer_spec.rb
|
355
380
|
- spec/opium/extensions/regexp_spec.rb
|
356
381
|
- spec/opium/extensions/string_spec.rb
|
382
|
+
- spec/opium/extensions/symbol_spec.rb
|
357
383
|
- spec/opium/extensions/time_spec.rb
|
384
|
+
- spec/opium/file_spec.rb
|
358
385
|
- spec/opium/model/attributable_spec.rb
|
386
|
+
- spec/opium/model/batchable/batch_spec.rb
|
387
|
+
- spec/opium/model/batchable/operation_spec.rb
|
388
|
+
- spec/opium/model/batchable_spec.rb
|
359
389
|
- spec/opium/model/callbacks_spec.rb
|
360
390
|
- spec/opium/model/connectable_spec.rb
|
361
391
|
- spec/opium/model/criteria_spec.rb
|