remotely 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -94,7 +94,7 @@ module Remotely
94
94
  # model object is returned, otherwise false.
95
95
  #
96
96
  def create(params={})
97
- new(params).save
97
+ new(params).tap { |n| n.save }
98
98
  end
99
99
 
100
100
  alias :create! :create
@@ -179,15 +179,8 @@ module Remotely
179
179
  # @return [Boolean] Did the save succeed.
180
180
  #
181
181
  def update_attributes(attrs={})
182
- @attribute_cache = self.attributes.dup
183
182
  self.attributes.merge!(attrs.symbolize_keys)
184
-
185
- if save && self.errors.empty?
186
- true
187
- else
188
- self.attributes = @attribute_cache
189
- false
190
- end
183
+ save
191
184
  end
192
185
 
193
186
  # Persist this object to the remote API.
@@ -205,8 +198,8 @@ module Remotely
205
198
  #
206
199
  # {"errors":{"attribute":["message", "message"]}}
207
200
  #
208
- # @return [Boolean, Model]
209
- # Remote API returns 200/201 status: the new/updated model object
201
+ # @return [Boolean]
202
+ # Remote API returns 200/201 status: true
210
203
  # Remote API returns any other status: false
211
204
  #
212
205
  def save
@@ -220,11 +213,11 @@ module Remotely
220
213
 
221
214
  if resp.status == status && !body.nil?
222
215
  self.attributes.merge!(body.symbolize_keys)
216
+ true
223
217
  else
224
218
  set_errors(body.delete("errors")) unless body.nil?
219
+ false
225
220
  end
226
-
227
- self
228
221
  end
229
222
 
230
223
  def savable_attributes
@@ -1,3 +1,3 @@
1
1
  module Remotely
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -156,7 +156,7 @@ describe Remotely::Model do
156
156
  end
157
157
 
158
158
  it "returns true when the save succeeds" do
159
- Adventure.new(attributes).save.should be_a Adventure
159
+ Adventure.new(attributes).save.should be_true
160
160
  end
161
161
 
162
162
  it "sets errors when a save fails" do
@@ -168,8 +168,8 @@ describe Remotely::Model do
168
168
  end
169
169
 
170
170
  context "when creating" do
171
+ let!(:adventure) { Adventure.new(name: "To Be Saved...") }
171
172
  it "merges in the response body to attributes on success" do
172
- adventure = Adventure.new(name: "To Be Saved...")
173
173
  stub_request(:post, %r(/adventures)).to_return(body: to_json(attributes.merge(name: "To Be Saved...", id: 2)), status: 201)
174
174
  adventure.save
175
175
  adventure.id.should == 2
@@ -178,7 +178,8 @@ describe Remotely::Model do
178
178
  it "sets errors on a failure" do
179
179
  body = Yajl.dump({errors: {base: ["error"]}})
180
180
  stub_request(:post, %r(/adventures)).to_return(status: 409, body: body)
181
- Adventure.new(name: "name").save.errors.should_not be_empty
181
+ adventure.save
182
+ adventure.errors.should_not be_empty
182
183
  end
183
184
  end
184
185
  end
@@ -220,13 +221,6 @@ describe Remotely::Model do
220
221
  subject.update_attributes(updates)
221
222
  subject.errors[:base].should include("error")
222
223
  end
223
-
224
- it "reverts the object's attributes if the save fails" do
225
- body = Yajl.dump({errors: {base: ["error"]}})
226
- stub_request(:put, %r[/adventures/1]).to_return(status: 500, body: body)
227
- subject.update_attributes(updates)
228
- subject.type.should == "MATHEMATICAL!"
229
- end
230
224
  end
231
225
 
232
226
  describe "#destroy" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-20 00:00:00.000000000Z
12
+ date: 2011-11-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &2152517620 !ruby/object:Gem::Requirement
16
+ requirement: &70188924310900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152517620
24
+ version_requirements: *70188924310900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2152517060 !ruby/object:Gem::Requirement
27
+ requirement: &70188924309560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.6.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152517060
35
+ version_requirements: *70188924309560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ZenTest
38
- requirement: &2152516520 !ruby/object:Gem::Requirement
38
+ requirement: &70188924308220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152516520
46
+ version_requirements: *70188924308220
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: autotest-growl
49
- requirement: &2152513940 !ruby/object:Gem::Requirement
49
+ requirement: &70188924307380 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152513940
57
+ version_requirements: *70188924307380
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &2152513340 !ruby/object:Gem::Requirement
60
+ requirement: &70188924306540 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2152513340
68
+ version_requirements: *70188924306540
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ruby-debug19
71
- requirement: &2152512920 !ruby/object:Gem::Requirement
71
+ requirement: &70188924305640 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2152512920
79
+ version_requirements: *70188924305640
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: ruby-debug-completion
82
- requirement: &2152512460 !ruby/object:Gem::Requirement
82
+ requirement: &70188924304980 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2152512460
90
+ version_requirements: *70188924304980
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: activesupport
93
- requirement: &2152511900 !ruby/object:Gem::Requirement
93
+ requirement: &70188924304340 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *2152511900
101
+ version_requirements: *70188924304340
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: activemodel
104
- requirement: &2152511300 !ruby/object:Gem::Requirement
104
+ requirement: &70188924302900 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *2152511300
112
+ version_requirements: *70188924302900
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: faraday
115
- requirement: &2152510660 !ruby/object:Gem::Requirement
115
+ requirement: &70188924301560 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 0.7.4
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *2152510660
123
+ version_requirements: *70188924301560
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: yajl-ruby
126
- requirement: &2152510160 !ruby/object:Gem::Requirement
126
+ requirement: &70188924300100 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,7 +131,7 @@ dependencies:
131
131
  version: 0.8.2
132
132
  type: :runtime
133
133
  prerelease: false
134
- version_requirements: *2152510160
134
+ version_requirements: *70188924300100
135
135
  description: Remote API based model associations.
136
136
  email:
137
137
  - me@mattenoble.com