storage_room 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/README.rdoc +10 -4
- data/Rakefile +3 -1
- data/TODO +7 -2
- data/VERSION +1 -1
- data/examples/authentication.rb +5 -3
- data/examples/create_entry.rb +8 -5
- data/examples/destroy_entry.rb +2 -2
- data/examples/get_collections.rb +2 -2
- data/examples/import_csv.rb +4 -4
- data/examples/search_entries.rb +2 -2
- data/examples/update_entry.rb +2 -2
- data/lib/console.rb +12 -0
- data/lib/storage_room.rb +73 -34
- data/lib/storage_room/accessors.rb +190 -0
- data/lib/storage_room/array.rb +3 -23
- data/lib/storage_room/embedded.rb +1 -1
- data/lib/storage_room/embeddeds/field.rb +28 -0
- data/lib/storage_room/embeddeds/fields/association_field.rb +17 -0
- data/lib/storage_room/embeddeds/fields/associations/many_association_field.rb +9 -0
- data/lib/storage_room/embeddeds/fields/associations/one_association_field.rb +9 -0
- data/lib/storage_room/embeddeds/fields/atomic/boolean_field.rb +6 -0
- data/lib/storage_room/embeddeds/fields/atomic/date_field.rb +6 -0
- data/lib/storage_room/embeddeds/fields/atomic/float_field.rb +6 -0
- data/lib/storage_room/embeddeds/fields/atomic/integer_field.rb +6 -0
- data/lib/storage_room/embeddeds/fields/atomic/string_field.rb +6 -0
- data/lib/storage_room/embeddeds/fields/atomic/time_field.rb +6 -0
- data/lib/storage_room/embeddeds/fields/atomic_field.rb +15 -0
- data/lib/storage_room/embeddeds/fields/compound/attachment_field.rb +6 -0
- data/lib/storage_room/embeddeds/fields/compound/file_field.rb +6 -0
- data/lib/storage_room/embeddeds/fields/compound/image_field.rb +6 -0
- data/lib/storage_room/embeddeds/fields/compound/location_field.rb +6 -0
- data/lib/storage_room/embeddeds/fields/compound_field.rb +10 -0
- data/lib/storage_room/embeddeds/file.rb +1 -1
- data/lib/storage_room/embeddeds/image.rb +6 -0
- data/lib/storage_room/embeddeds/location.rb +2 -1
- data/lib/storage_room/extensions/const_defined.rb +12 -0
- data/lib/storage_room/identity_map.rb +117 -0
- data/lib/storage_room/model.rb +19 -23
- data/lib/storage_room/models/collection.rb +76 -11
- data/lib/storage_room/models/entry.rb +6 -32
- data/lib/storage_room/plugins.rb +22 -0
- data/lib/storage_room/proxy.rb +49 -0
- data/lib/storage_room/{base.rb → resource.rb} +13 -36
- data/spec/fixtures/collection.json +0 -16
- data/spec/spec_helper.rb +1 -0
- data/spec/storage_room/accessors_spec.rb +107 -0
- data/spec/storage_room/array_spec.rb +13 -9
- data/spec/storage_room/embedded_spec.rb +5 -1
- data/spec/storage_room/embeddeds/field_spec.rb +25 -0
- data/spec/storage_room/embeddeds/fields/association_field_spec.rb +29 -0
- data/spec/storage_room/embeddeds/fields/associations/many_association_field_spec.rb +21 -0
- data/spec/storage_room/embeddeds/fields/associations/one_association_field_spec.rb +19 -0
- data/spec/storage_room/embeddeds/fields/atomic/boolean_field_spec.rb +5 -0
- data/spec/storage_room/embeddeds/fields/atomic/date_field_spec.rb +5 -0
- data/spec/storage_room/embeddeds/fields/atomic/float_field_spec.rb +5 -0
- data/spec/storage_room/embeddeds/fields/atomic/integer_field_spec.rb +5 -0
- data/spec/storage_room/embeddeds/fields/atomic/string_field_spec.rb +5 -0
- data/spec/storage_room/embeddeds/fields/atomic/time_field_spec.rb +5 -0
- data/spec/storage_room/embeddeds/fields/atomic_field_spec.rb +27 -0
- data/spec/storage_room/embeddeds/fields/compound/attachment_field_spec.rb +5 -0
- data/spec/storage_room/embeddeds/fields/compound/file_field_spec.rb +5 -0
- data/spec/storage_room/embeddeds/fields/compound/image_field_spec.rb +5 -0
- data/spec/storage_room/embeddeds/fields/compound/location_field_spec.rb +5 -0
- data/spec/storage_room/embeddeds/fields/compound_field_spec.rb +17 -0
- data/spec/storage_room/embeddeds/location_spec.rb +13 -1
- data/spec/storage_room/identity_map_spec.rb +53 -0
- data/spec/storage_room/model_spec.rb +70 -50
- data/spec/storage_room/models/collection_spec.rb +57 -14
- data/spec/storage_room/models/entry_spec.rb +16 -20
- data/spec/storage_room/proxy_spec.rb +58 -0
- data/spec/storage_room/resource_spec.rb +98 -0
- data/spec/storage_room_spec.rb +45 -9
- data/storage_room.gemspec +48 -9
- data/tasks/storage_room.rake +3 -0
- metadata +49 -10
- data/lib/storage_room/attributes.rb +0 -46
- data/lib/storage_room/field.rb +0 -8
- data/spec/storage_room/attributes_spec.rb +0 -82
- data/spec/storage_room/base_spec.rb +0 -118
- data/spec/storage_room/field_spec.rb +0 -5
@@ -1,5 +1,9 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
|
+
class PointOfInterest < StorageRoom::Model
|
4
|
+
key :value
|
5
|
+
end
|
6
|
+
|
3
7
|
describe StorageRoom::Array do
|
4
8
|
context "Class" do
|
5
9
|
context "Configuration" do
|
@@ -22,10 +26,10 @@ describe StorageRoom::Array do
|
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
|
-
describe "#
|
29
|
+
describe "#set_from_response_data" do
|
26
30
|
before(:each) do
|
27
|
-
@hash = {'@page' => 1, 'resources' => [{'
|
28
|
-
@array.
|
31
|
+
@hash = {'@page' => 1, 'resources' => [{'value' => 1, '@type' => 'PointOfInterest'}, {'value' => 2, '@type' => 'PointOfInterest'}]}
|
32
|
+
@array.set_from_response_data(@hash)
|
29
33
|
end
|
30
34
|
|
31
35
|
it "should set meta data" do
|
@@ -34,10 +38,10 @@ describe StorageRoom::Array do
|
|
34
38
|
|
35
39
|
it "should set resources" do
|
36
40
|
@array.resources.should have(2).items
|
37
|
-
@array.resources[0].should be_an_instance_of(
|
38
|
-
@array.resources[0]
|
39
|
-
@array.resources[1].should be_an_instance_of(
|
40
|
-
@array.resources[1]
|
41
|
+
@array.resources[0].should be_an_instance_of(PointOfInterest)
|
42
|
+
@array.resources[0].value.should == 1
|
43
|
+
@array.resources[1].should be_an_instance_of(PointOfInterest)
|
44
|
+
@array.resources[1].value.should == 2
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
@@ -54,7 +58,7 @@ describe StorageRoom::Array do
|
|
54
58
|
end
|
55
59
|
|
56
60
|
it "should load when present" do
|
57
|
-
@array[:@next_page_url] = "url"
|
61
|
+
@array.response_data[:@next_page_url] = "url"
|
58
62
|
@array.stub(:reload)
|
59
63
|
@array.should_receive(:reload)
|
60
64
|
@array.load_next_page!.should be_true
|
@@ -67,7 +71,7 @@ describe StorageRoom::Array do
|
|
67
71
|
end
|
68
72
|
|
69
73
|
it "should load when present" do
|
70
|
-
@array[:@previous_page_url] = "url"
|
74
|
+
@array.response_data[:@previous_page_url] = "url"
|
71
75
|
@array.stub(:reload)
|
72
76
|
@array.should_receive(:reload)
|
73
77
|
@array.load_previous_page!.should be_true
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StorageRoom::Field do
|
4
|
+
before(:each) do
|
5
|
+
@field = StorageRoom::Field.new
|
6
|
+
end
|
7
|
+
|
8
|
+
context "Configuration" do
|
9
|
+
it "should have keys" do
|
10
|
+
keys = StorageRoom::Field.attribute_options.keys
|
11
|
+
|
12
|
+
[:name, :identifier, :hint, :input_type, :required, :unique, :maximum_length, :minimum_length, :minimum_number, :maximum_number, :minimum_size, :maximum_size].each do |key|
|
13
|
+
keys.should include(key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "Methods" do
|
19
|
+
describe "#add_to_entry_class" do
|
20
|
+
it "should have method" do
|
21
|
+
@field.add_to_entry_class(StorageRoom::Entry)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StorageRoom::AssociationField do
|
4
|
+
before(:each) do
|
5
|
+
@field = StorageRoom::AssociationField.new(:collection_url => 'URL')
|
6
|
+
end
|
7
|
+
|
8
|
+
context "Configuration" do
|
9
|
+
it "should have keys" do
|
10
|
+
keys = StorageRoom::AssociationField.attribute_options.keys
|
11
|
+
|
12
|
+
[:collection_url].each do |key|
|
13
|
+
keys.should include(key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "Methods" do
|
19
|
+
describe "#collection" do
|
20
|
+
it "should return collection" do
|
21
|
+
collection = StorageRoom::Collection.new
|
22
|
+
StorageRoom::Collection.stub(:load).and_return(collection)
|
23
|
+
StorageRoom::Collection.should_receive(:load).with('URL')
|
24
|
+
|
25
|
+
@field.collection.should == collection
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StorageRoom::ManyAssociationField do
|
4
|
+
describe StorageRoom::OneAssociationField do
|
5
|
+
before(:each) do
|
6
|
+
@field = StorageRoom::ManyAssociationField.new(:collection_url => 'URL', :identifier => 'identifier')
|
7
|
+
end
|
8
|
+
|
9
|
+
context "Methods" do
|
10
|
+
describe "#add_to_entry_class" do
|
11
|
+
it "should add many" do
|
12
|
+
StorageRoom::Collection.stub(:load)
|
13
|
+
|
14
|
+
klass = StorageRoom::Entry
|
15
|
+
klass.should_receive(:many).with('identifier')
|
16
|
+
@field.add_to_entry_class(klass)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StorageRoom::OneAssociationField do
|
4
|
+
before(:each) do
|
5
|
+
@field = StorageRoom::OneAssociationField.new(:collection_url => 'URL', :identifier => 'identifier')
|
6
|
+
end
|
7
|
+
|
8
|
+
context "Methods" do
|
9
|
+
describe "#add_to_entry_class" do
|
10
|
+
it "should add one" do
|
11
|
+
StorageRoom::Collection.stub(:load)
|
12
|
+
|
13
|
+
klass = StorageRoom::Entry
|
14
|
+
klass.should_receive(:one).with('identifier')
|
15
|
+
@field.add_to_entry_class(klass)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StorageRoom::AtomicField do
|
4
|
+
before(:each) do
|
5
|
+
@field = StorageRoom::AtomicField.new(:identifier => 'identifier')
|
6
|
+
end
|
7
|
+
|
8
|
+
context "Configuration" do
|
9
|
+
it "should have keys" do
|
10
|
+
keys = StorageRoom::AtomicField.attribute_options.keys
|
11
|
+
|
12
|
+
[:default_value, :choices, :include_blank_choice].each do |key|
|
13
|
+
keys.should include(key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "Methods" do
|
19
|
+
describe "#add_to_entry_class" do
|
20
|
+
it "should add key" do
|
21
|
+
klass = StorageRoom::Entry
|
22
|
+
klass.should_receive(:key).with('identifier')
|
23
|
+
@field.add_to_entry_class(klass)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StorageRoom::CompoundField do
|
4
|
+
before(:each) do
|
5
|
+
@field = StorageRoom::CompoundField.new(:identifier => 'identifier')
|
6
|
+
end
|
7
|
+
|
8
|
+
context "Methods" do
|
9
|
+
describe "#add_to_entry_class" do
|
10
|
+
it "should add one" do
|
11
|
+
klass = StorageRoom::Entry
|
12
|
+
klass.should_receive(:one).with('identifier')
|
13
|
+
@field.add_to_entry_class(klass)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,5 +1,17 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
2
|
|
3
3
|
describe StorageRoom::Location do
|
4
|
-
|
4
|
+
before(:each) do
|
5
|
+
@location = StorageRoom::Location.new(:lat => 1, :lng => 2)
|
6
|
+
end
|
7
|
+
|
8
|
+
context "Configuration" do
|
9
|
+
it "should have keys" do
|
10
|
+
keys = StorageRoom::Location.attribute_options.keys
|
11
|
+
|
12
|
+
[:lat, :lng].each do |key|
|
13
|
+
keys.should include(key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
5
17
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Recipe < StorageRoom::Entry
|
4
|
+
key :name
|
5
|
+
end
|
6
|
+
|
7
|
+
describe StorageRoom::IdentityMap do
|
8
|
+
before(:each) do
|
9
|
+
@response_data = {'@url' => 'URL', '@type' => 'Recipe', 'name' => 'NAME'}
|
10
|
+
|
11
|
+
@recipe = Recipe.new_from_response_data(@response_data)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "Module Methods" do
|
15
|
+
describe "#models" do
|
16
|
+
it "should return set" do
|
17
|
+
set = StorageRoom::IdentityMap.models
|
18
|
+
set.should be_an_instance_of(Set)
|
19
|
+
set.should include(StorageRoom::Resource)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#clear" do
|
24
|
+
it "should remove objects" do
|
25
|
+
StorageRoom::Resource.identity_map['URL'] = 1
|
26
|
+
StorageRoom::Resource.identity_map.should have(1).item
|
27
|
+
|
28
|
+
StorageRoom::IdentityMap.clear
|
29
|
+
StorageRoom::Resource.identity_map.should have(0).items
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "Class Methods" do
|
35
|
+
describe "#new_from_response_data" do
|
36
|
+
it "should return existing object from identity map" do
|
37
|
+
response_data = {'@url' => 'URL', '@type' => 'Recipe'}
|
38
|
+
|
39
|
+
recipe = Recipe.new_from_response_data(response_data)
|
40
|
+
recipe.should == @recipe
|
41
|
+
recipe.name.should == 'NAME'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return new object" do
|
45
|
+
response_data = {'@url' => 'URL2', '@type' => 'Recipe', 'name' => 'NAME2'}
|
46
|
+
|
47
|
+
recipe = Recipe.new_from_response_data(response_data)
|
48
|
+
recipe.should_not == @recipe
|
49
|
+
recipe.name.should == 'NAME2'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,6 +1,28 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
|
+
class Contributor < StorageRoom::Entry
|
4
|
+
|
5
|
+
end
|
6
|
+
|
7
|
+
class Author < StorageRoom::Entry
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class Recipe < StorageRoom::Entry
|
12
|
+
key :name
|
13
|
+
key :ingredients
|
14
|
+
|
15
|
+
one :author
|
16
|
+
many :contributors
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
3
21
|
describe StorageRoom::Model do
|
22
|
+
before(:each) do
|
23
|
+
@model = Recipe.new(:name => 'NAME')
|
24
|
+
end
|
25
|
+
|
4
26
|
context "Class" do
|
5
27
|
context "Methods" do
|
6
28
|
describe "#show_path" do
|
@@ -59,15 +81,10 @@ describe StorageRoom::Model do
|
|
59
81
|
end
|
60
82
|
end
|
61
83
|
|
62
|
-
context "Instance" do
|
63
|
-
before(:each) do
|
64
|
-
@model = StorageRoom::Model.new(:test => 1, :@attr => 2)
|
65
|
-
end
|
66
|
-
|
84
|
+
context "Instance" do
|
67
85
|
describe "#initialize" do
|
68
86
|
it "should set attributes" do
|
69
|
-
@model
|
70
|
-
@model[:@attr].should == 2
|
87
|
+
@model.name.should == 'NAME'
|
71
88
|
end
|
72
89
|
|
73
90
|
it "should set new record" do
|
@@ -79,18 +96,17 @@ describe StorageRoom::Model do
|
|
79
96
|
end
|
80
97
|
end
|
81
98
|
|
82
|
-
describe "#
|
99
|
+
describe "#set_from_response_data" do
|
83
100
|
before(:each) do
|
84
|
-
@model.
|
101
|
+
@model.set_from_response_data('ingredients' => 'INGREDIENTS', '@version' => 2)
|
85
102
|
end
|
86
103
|
|
87
104
|
it "should reset attributes" do
|
88
|
-
@model
|
89
|
-
@model[:@attr].should be_nil
|
105
|
+
@model.name.should be_nil
|
90
106
|
end
|
91
107
|
|
92
108
|
it "should set new attributes" do
|
93
|
-
@model
|
109
|
+
@model.ingredients.should == 'INGREDIENTS'
|
94
110
|
end
|
95
111
|
|
96
112
|
it "should set new record" do
|
@@ -127,9 +143,12 @@ describe StorageRoom::Model do
|
|
127
143
|
end
|
128
144
|
|
129
145
|
describe "#new_record?" do
|
130
|
-
it "should
|
146
|
+
it "should return true" do
|
131
147
|
@model.should be_new_record
|
132
|
-
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should return false" do
|
151
|
+
@model.response_data['@version'] = 3
|
133
152
|
@model.should_not be_new_record
|
134
153
|
end
|
135
154
|
end
|
@@ -146,26 +165,34 @@ describe StorageRoom::Model do
|
|
146
165
|
end
|
147
166
|
|
148
167
|
it "should update on existing record" do
|
149
|
-
@model.
|
168
|
+
@model.stub(:new_record?).and_return(false)
|
150
169
|
@model.should_receive(:update)
|
151
170
|
@model.save
|
152
171
|
end
|
153
172
|
end
|
154
173
|
|
155
174
|
describe "#as_json" do
|
156
|
-
it "should return hash
|
157
|
-
|
175
|
+
it "should return hash" do
|
176
|
+
contributor = Contributor.new
|
177
|
+
contributor.response_data[:@url] = "CONTRIBUTOR_URL"
|
178
|
+
|
179
|
+
author = Author.new
|
180
|
+
author.response_data[:@url] = "AUTHOR_URL"
|
181
|
+
|
182
|
+
entry = Recipe.new(:name => "NAME", :ingredients => "INGREDIENTS", :contributors => [contributor], :author => author)
|
158
183
|
hash = entry.as_json
|
159
184
|
|
160
|
-
hash['entry'][
|
161
|
-
hash['entry'][
|
185
|
+
hash['entry']['name'].should == "NAME"
|
186
|
+
hash['entry']['ingredients'].should == "INGREDIENTS"
|
187
|
+
hash['entry']['author']['url'].should == 'AUTHOR_URL'
|
188
|
+
hash['entry']['contributors'][0].should == {'url' => 'CONTRIBUTOR_URL'}
|
162
189
|
end
|
163
190
|
end
|
164
191
|
|
165
192
|
describe "#reload" do
|
166
193
|
it "should load" do
|
167
194
|
collection = StorageRoom::Collection.new
|
168
|
-
collection[:@url] = '/collections/1'
|
195
|
+
collection.response_data[:@url] = '/collections/1'
|
169
196
|
stub_request(:get, stub_url('/collections/1')).to_return(:body => fixture_file('collection.json'), :status => 200)
|
170
197
|
|
171
198
|
collection.reload
|
@@ -175,60 +202,53 @@ describe StorageRoom::Model do
|
|
175
202
|
|
176
203
|
describe "#create" do
|
177
204
|
it "should create" do
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
guidebook.create
|
185
|
-
guidebook[:name].should == 'Guidebooks'
|
205
|
+
guidebooks = StorageRoom::Collection.new
|
206
|
+
stub_request(:post, stub_url('/collections')).to_return(:body => fixture_file('collection.json'), :status => 201)
|
207
|
+
|
208
|
+
guidebooks.create
|
209
|
+
guidebooks.should_not be_new_record
|
186
210
|
end
|
187
211
|
|
188
212
|
it "should have errors on validation error" do
|
189
|
-
|
190
|
-
klass = StorageRoom::Entry.class_with_options('Guidebook', :collection_path => collection_path)
|
191
|
-
guidebook = klass.new
|
213
|
+
guidebooks = StorageRoom::Collection.new
|
192
214
|
|
193
|
-
stub_request(:post, stub_url('/collections
|
215
|
+
stub_request(:post, stub_url('/collections')).to_return(:body => fixture_file('validation_error.json'), :status => 422)
|
194
216
|
|
195
|
-
|
196
|
-
|
217
|
+
guidebooks.create
|
218
|
+
guidebooks.should be_new_record
|
197
219
|
|
198
|
-
|
220
|
+
guidebooks.errors.should have(1).items
|
199
221
|
end
|
200
222
|
end
|
201
223
|
|
202
224
|
describe "#update" do
|
225
|
+
before(:each) do
|
226
|
+
@collection = StorageRoom::Collection.new
|
227
|
+
@collection.response_data[:@url] = '/collections/1'
|
228
|
+
@collection.response_data[:@version] = 1
|
229
|
+
end
|
230
|
+
|
203
231
|
it "should update" do
|
204
|
-
collection = StorageRoom::Collection.new
|
205
|
-
collection.instance_variable_set(:@new_record, false)
|
206
|
-
collection[:@url] = '/collections/1'
|
207
|
-
|
208
232
|
stub_request(:put, stub_url('/collections/1')).to_return(:body => fixture_file('collection.json'), :status => 200)
|
209
233
|
|
210
|
-
collection.update
|
211
|
-
collection[
|
234
|
+
@collection.update
|
235
|
+
@collection.response_data[:@version].should == 2
|
212
236
|
end
|
213
237
|
|
214
238
|
it "should have errors on validation error" do
|
215
|
-
collection = StorageRoom::Collection.new
|
216
|
-
collection.instance_variable_set(:@new_record, false)
|
217
|
-
collection[:@url] = '/collections/1'
|
218
|
-
|
219
239
|
stub_request(:put, stub_url('/collections/1')).to_return(:body => fixture_file('validation_error.json'), :status => 422)
|
220
240
|
|
221
|
-
collection.update
|
222
|
-
collection[
|
223
|
-
collection.errors.should have(1).items
|
241
|
+
@collection.update
|
242
|
+
@collection.response_data[:@version].should == 1
|
243
|
+
@collection.errors.should have(1).items
|
224
244
|
end
|
225
245
|
end
|
226
246
|
|
227
247
|
describe "#destroy" do
|
228
248
|
it "should destroy" do
|
229
249
|
collection = StorageRoom::Collection.new
|
230
|
-
collection.
|
231
|
-
collection[:@
|
250
|
+
collection.response_data[:@url] = '/collections/1'
|
251
|
+
collection.response_data[:@version] = 1
|
232
252
|
|
233
253
|
stub_request(:delete, stub_url('/collections/1')).to_return(:status => 200)
|
234
254
|
|