mince 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,99 +1,141 @@
1
1
  require_relative '../../../lib/mince/model'
2
2
 
3
- describe Mince::Model do
4
- let(:klass) do
5
- Class.new do
6
- include Mince::Model
3
+ module Mince
4
+ describe Model do
5
+ let(:klass) do
6
+ Class.new do
7
+ include Mince::Model
8
+
9
+ data_model Class.new
10
+
11
+ field :meh
12
+ field :foo, assignable: true
13
+ field :bar, assignable: false
14
+ fields :baz, :qaaz
15
+ end
16
+ end
17
+
18
+ let(:meh) { mock 'meh' }
19
+ let(:foo) { mock 'foo' }
20
+ let(:bar) { mock 'bar' }
21
+ let(:baz) { mock 'baz' }
22
+ let(:qaaz) { mock 'qaaz' }
7
23
 
8
- data_model Class.new
24
+ subject { klass.new(meh: meh, foo: foo, bar: bar, baz: baz, qaaz: qaaz) }
9
25
 
10
- field :meh
11
- field :foo, assignable: true
12
- field :bar, assignable: false
13
- fields :baz, :qaaz
26
+ before do
27
+ subject.data_model.stub(infer_fields?: false)
28
+ klass.data_model.stub(infer_fields?: false)
14
29
  end
15
- end
16
30
 
17
- let(:meh) { mock 'meh' }
18
- let(:foo) { mock 'foo' }
19
- let(:bar) { mock 'bar' }
20
- let(:baz) { mock 'baz' }
21
- let(:qaaz) { mock 'qaaz' }
31
+ it 'initializes the object and assigns values to the fields' do
32
+ subject.meh.should == meh
33
+ subject.foo.should == foo
34
+ subject.bar.should == bar
35
+ subject.baz.should == baz
36
+ subject.qaaz.should == qaaz
37
+ end
22
38
 
23
- subject { klass.new(meh: meh, foo: foo, bar: bar, baz: baz, qaaz: qaaz) }
39
+ it 'can set the assignable fields outside of the initilizer' do
40
+ subject.foo = 'foo1'
41
+ subject.foo.should == 'foo1'
42
+ subject.attributes = { foo: 'foo2' }
43
+ subject.foo.should == 'foo2'
44
+ end
24
45
 
25
- it 'initializes the object and assigns values to the fields' do
26
- subject.meh.should == meh
27
- subject.foo.should == foo
28
- subject.bar.should == bar
29
- subject.baz.should == baz
30
- subject.qaaz.should == qaaz
31
- end
46
+ it 'cannot set the readonly field outside of the initilizer' do
47
+ subject.attributes = { bar: 'bar1' }
48
+ subject.bar.should == bar
49
+ end
32
50
 
33
- it 'can set the assignable fields outside of the initilizer' do
34
- subject.foo = 'foo1'
35
- subject.foo.should == 'foo1'
36
- subject.attributes = { foo: 'foo2' }
37
- subject.foo.should == 'foo2'
38
- end
51
+ it 'fields are readonly by default' do
52
+ subject.attributes = { meh: 'meh1' }
53
+ subject.meh.should == meh
54
+ end
39
55
 
40
- it 'cannot set the readonly field outside of the initilizer' do
41
- subject.attributes = { bar: 'bar1' }
42
- subject.bar.should == bar
43
- end
56
+ describe 'saving' do
57
+ let(:id) { mock 'id' }
58
+ let(:data_fields) { subject.fields }
44
59
 
45
- it 'fields are readonly by default' do
46
- subject.attributes = { meh: 'meh1' }
47
- subject.meh.should == meh
48
- end
60
+ before do
61
+ subject.data_model.stub(:data_fields).and_return(data_fields)
62
+ end
49
63
 
50
- describe 'saving' do
51
- let(:id) { mock 'id' }
52
- let(:data_fields) { subject.fields }
64
+ context 'when the data model is inferring fields from the model' do
65
+ before do
66
+ subject.data_model.stub(:store => id, infer_fields?: true, data_fields: nil)
67
+ end
53
68
 
54
- before do
55
- subject.data_model.stub(:data_fields).and_return(data_fields)
56
- end
69
+ it 'stores the model' do
70
+ subject.data_model.should_receive(:store).with(subject).and_return(id)
71
+
72
+ subject.save
73
+ end
57
74
 
58
- context 'when the model has fields that are not defined in the data model' do
59
- let(:data_fields) { subject.fields - extra_fields }
60
- let(:extra_fields) { subject.fields[0..-2] }
75
+ it 'assigns the id' do
76
+ subject.save
61
77
 
62
- it 'raises an exception with a message' do
63
- expect { subject.save }.to raise_error("Tried to save a #{subject.class.name} with fields not specified in #{subject.data_model.name}: #{extra_fields.join(', ')}")
78
+ subject.id.should == id
79
+ end
64
80
  end
65
- end
66
81
 
67
- context 'when it has not yet been persisted to the mince data model' do
68
- before do
69
- subject.data_model.stub(:store => id)
82
+ context 'when the model has fields that are not defined in the data model' do
83
+ let(:data_fields) { subject.fields - extra_fields }
84
+ let(:extra_fields) { subject.fields[0..-2] }
85
+
86
+ it 'raises an exception with a message' do
87
+ expect { subject.save }.to raise_error("Tried to save a #{subject.class.name} with fields not specified in #{subject.data_model.name}: #{extra_fields.join(', ')}")
88
+ end
70
89
  end
71
90
 
72
- it 'stores the model' do
73
- subject.data_model.should_receive(:store).with(subject).and_return(id)
91
+ context 'when it has not yet been persisted to the mince data model' do
92
+ before do
93
+ subject.data_model.stub(:store => id)
94
+ end
95
+
96
+ it 'stores the model' do
97
+ subject.data_model.should_receive(:store).with(subject).and_return(id)
98
+
99
+ subject.save
100
+ end
74
101
 
75
- subject.save
102
+ it 'assigns the id' do
103
+ subject.save
104
+
105
+ subject.id.should == id
106
+ end
76
107
  end
77
108
 
78
- it 'assigns the id' do
79
- subject.save
109
+ context 'when it has already been persisted to the mince data model' do
110
+ let(:subject) { klass.new(id: id) }
111
+
112
+ it 'updates the model' do
113
+ subject.data_model.should_receive(:update).with(subject)
80
114
 
81
- subject.id.should == id
115
+ subject.save
116
+ end
82
117
  end
83
118
  end
119
+ end
84
120
 
85
- context 'when it has already been persisted to the mince data model' do
86
- let(:subject) { klass.new(id: id) }
121
+ describe Model, "Query Methods:" do
122
+ let(:klass) do
123
+ Class.new do
124
+ include Mince::Model
87
125
 
88
- it 'updates the model' do
89
- subject.data_model.should_receive(:update).with(subject)
126
+ data_model Class.new
90
127
 
91
- subject.save
128
+ field :meh
129
+ field :foo, assignable: true
130
+ field :bar, assignable: false
131
+ fields :baz, :qaaz
92
132
  end
93
133
  end
94
- end
95
134
 
96
- describe "Query Methods:" do
135
+ before do
136
+ klass.data_model.stub(infer_fields?: false)
137
+ end
138
+
97
139
  it 'provides a way to easily create a new record' do
98
140
  model = mock 'model'
99
141
  data = mock 'data'
@@ -135,4 +177,3 @@ describe Mince::Model do
135
177
  end
136
178
  end
137
179
  end
138
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mince
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Simpson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-29 00:00:00.000000000 Z
12
+ date: 2013-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -160,6 +160,7 @@ extensions: []
160
160
  extra_rdoc_files: []
161
161
  files:
162
162
  - lib/mince/config.rb
163
+ - lib/mince/data_model/timestamps.rb
163
164
  - lib/mince/data_model.rb
164
165
  - lib/mince/model/data_model.rb
165
166
  - lib/mince/model/fields.rb
@@ -171,11 +172,14 @@ files:
171
172
  - lib/mince.rb
172
173
  - LICENSE.txt
173
174
  - README.md
175
+ - spec/integration/inferred_data_fields_spec.rb
174
176
  - spec/integration/mince_data_model_spec.rb
175
177
  - spec/integration/mince_model_spec.rb
176
178
  - spec/support/shared_examples/model_data_model_example.rb
177
179
  - spec/support/shared_examples/model_finders_example.rb
178
180
  - spec/units/mince/config_spec.rb
181
+ - spec/units/mince/data_model/inferred_fields_spec.rb
182
+ - spec/units/mince/data_model/timestamps_spec.rb
179
183
  - spec/units/mince/data_model_spec.rb
180
184
  - spec/units/mince/interface_example_spec.rb
181
185
  - spec/units/mince/model/data_model_spec.rb
@@ -206,11 +210,14 @@ signing_key:
206
210
  specification_version: 4
207
211
  summary: Ruby library to provide a light weight flexible ORM
208
212
  test_files:
213
+ - spec/integration/inferred_data_fields_spec.rb
209
214
  - spec/integration/mince_data_model_spec.rb
210
215
  - spec/integration/mince_model_spec.rb
211
216
  - spec/support/shared_examples/model_data_model_example.rb
212
217
  - spec/support/shared_examples/model_finders_example.rb
213
218
  - spec/units/mince/config_spec.rb
219
+ - spec/units/mince/data_model/inferred_fields_spec.rb
220
+ - spec/units/mince/data_model/timestamps_spec.rb
214
221
  - spec/units/mince/data_model_spec.rb
215
222
  - spec/units/mince/interface_example_spec.rb
216
223
  - spec/units/mince/model/data_model_spec.rb