panda 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 1.4.2 (February 16, 2011)
2
+
3
+ Features:
4
+
5
+ - Raises the api message on `save!`
6
+ - Added `update_attributes!` method
7
+
8
+ Bugfixes:
9
+
10
+ - `reload` method was raising after `create`
11
+
1
12
  ## 1.4.1 (February 4, 2011)
2
13
 
3
14
  Features:
data/lib/panda/base.rb CHANGED
@@ -48,7 +48,7 @@ module Panda
48
48
  def load_and_reset(response)
49
49
  load_response(response)
50
50
  end
51
-
51
+
52
52
  def perform_reload(args={})
53
53
  raise "RecordNotFound" if new?
54
54
 
@@ -26,7 +26,7 @@ module Panda
26
26
  private
27
27
 
28
28
  def build_resource(attributes)
29
- Panda::const_get("#{sti_name}").new(attributes.merge(:cloud_id => cloud.id))
29
+ Panda::const_get("#{sti_name}").new(attributes.merge('cloud_id' => cloud.id))
30
30
  end
31
31
  end
32
32
 
@@ -6,18 +6,21 @@ module Panda
6
6
  end
7
7
 
8
8
  def save!
9
- save || raise("Resource invalid")
9
+ save || raise(errors.last)
10
10
  end
11
11
 
12
12
  def update_attribute(name, value)
13
- self.send("#{name}=".to_sym, value)
14
- self.save
13
+ send("#{name}=".to_sym, value) && save
15
14
  end
16
15
 
17
16
  def update_attributes(attributes)
18
17
  load(attributes) && save
19
18
  end
20
19
 
20
+ def update_attributes!(attributes)
21
+ update_attributes(attributes) || raise(errors.last)
22
+ end
23
+
21
24
  def update
22
25
  uri = replace_pattern_with_self_variables(self.class.one_path)
23
26
  response = connection.put(uri, @changed_attributes)
@@ -38,5 +38,11 @@ module Panda
38
38
  self
39
39
  end
40
40
 
41
+ private
42
+
43
+ def load_and_reset(response)
44
+ load_response(response.merge('cloud_id' => cloud.id))
45
+ end
46
+
41
47
  end
42
48
  end
data/lib/panda/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Panda
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
data/spec/cloud_spec.rb CHANGED
@@ -111,6 +111,19 @@ describe Panda::Cloud do
111
111
  @cloud = Panda::Cloud.create(:s3_videos_bucket => 'videobucket', :user_aws_key => 'myaccesskey', :user_aws_secret => 'mysecretkey')
112
112
  @cloud.s3_videos_bucket.should == "videobucket"
113
113
  end
114
+
115
+
116
+ it "should create a cloud and reload" do
117
+ cloud_json = "{\"s3_videos_bucket\":\"videobucket\",\"id\":\"my_new_cloud_id\"}"
118
+ stub_http_request(:post, /http:\/\/api.example.com:85\/v2\/clouds.json/).
119
+ to_return(:body => cloud_json)
120
+
121
+ stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_new_cloud_id.json/).
122
+ to_return(:body => cloud_json)
123
+
124
+ @cloud = Panda::Cloud.create(:s3_videos_bucket => 'videobucket', :user_aws_key => 'myaccesskey', :user_aws_secret => 'mysecretkey')
125
+ @cloud.reload.should == @cloud
126
+ end
114
127
 
115
128
  end
116
129
 
data/spec/video_spec.rb CHANGED
@@ -183,6 +183,19 @@ describe Panda::Video do
183
183
  video.id.should == "123"
184
184
  end
185
185
 
186
+ it "should create a video and reload" do
187
+ video_json = "{\"source_url\":\"url_panda.mp4\",\"id\":\"123\"}"
188
+
189
+ stub_http_request(:post, /api.example.com:85\/v2\/videos.json/).
190
+ with(:body => /source_url=url_panda.mp4/).
191
+ to_return(:body => video_json)
192
+
193
+ stub_http_request(:get, /api.example.com:85\/v2\/videos\/123.json/).to_return(:body => video_json)
194
+
195
+ video = Panda::Video.create(:source_url => "url_panda.mp4")
196
+ video.reload.should == video
197
+ end
198
+
186
199
  it "should create a video using class method and a block" do
187
200
  video_json = "{\"source_url\":\"url_panda.mp4\",\"id\":\"123\"}"
188
201
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panda
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 1
10
- version: 1.4.1
9
+ - 2
10
+ version: 1.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - New Bamboo
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-04 00:00:00 +00:00
18
+ date: 2011-02-16 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency