amfetamine 0.3.1 → 0.3.2

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 0.3.2
2
+ - fix for Object#save return value with disabled caching
3
+
1
4
  0.3.1
2
5
  - memcached_instance Dalli::Client configuration setting changes (it should now start with "memcached://")
3
6
 
@@ -19,7 +19,7 @@ module Amfetamine
19
19
  key = opts[:nested_path] || self.find_path(id)
20
20
  data = get_data(key, opts[:conditions])
21
21
  if data[:status] == :success
22
- val = build_object(data[:body])
22
+ val = build_object(data[:body])
23
23
  else
24
24
  nil
25
25
  end
@@ -99,17 +99,17 @@ module Amfetamine
99
99
  end
100
100
 
101
101
  run_callbacks(:save) do
102
- response = if self.new?
103
- path = self.belongs_to_relationship? ? belongs_to_relationships.first.rest_path : rest_path
104
- self.class.handle_request(:post, path, {:body => {class_name.to_sym => self.to_hash}})
105
- else
106
- # Needs cleaning up, also needs to work with multiple belongs_to relationships (optional, I guess)
107
- path = self.belongs_to_relationship? ? belongs_to_relationships.first.singular_path : singular_path
108
- self.class.handle_request(:put, path, {:body => {class_name.to_sym => self.to_hash}})
109
- end
102
+ response =
103
+ if self.new?
104
+ path = self.belongs_to_relationship? ? belongs_to_relationships.first.rest_path : rest_path
105
+ self.class.handle_request(:post, path, {:body => {class_name.to_sym => self.to_hash}})
106
+ else
107
+ # Needs cleaning up, also needs to work with multiple belongs_to relationships (optional, I guess)
108
+ path = self.belongs_to_relationship? ? belongs_to_relationships.first.singular_path : singular_path
109
+ self.class.handle_request(:put, path, {:body => {class_name.to_sym => self.to_hash}})
110
+ end
110
111
 
111
112
  if handle_response(response)
112
-
113
113
  begin
114
114
  update_attributes_from_response(response[:body])
115
115
  ensure
@@ -119,7 +119,11 @@ module Amfetamine
119
119
  path = self.belongs_to_relationship? ? belongs_to_relationships.first.singular_path : singular_path
120
120
  self.cache_key = path
121
121
 
122
- cache.set(path, self.to_cacheable) if self.cacheable?
122
+ if self.cacheable?
123
+ cache.set(path, self.to_cacheable)
124
+ else
125
+ true # return true for successful updates
126
+ end
123
127
  else
124
128
  false
125
129
  end
@@ -153,7 +157,6 @@ module Amfetamine
153
157
  cache.delete(r.rest_path + cc)
154
158
  end
155
159
  end
156
-
157
160
  condition_keys = cache.get("#{rest_path}_conditions") || []
158
161
  condition_keys.each do |cc|
159
162
  cache.delete(rest_path + cc)
@@ -162,9 +165,6 @@ module Amfetamine
162
165
  end
163
166
  end
164
167
 
165
-
166
-
167
-
168
168
  def update_attributes(attrs)
169
169
  return true if attrs.all? { |k,v| self.send(k) == v } # Don't update if no attributes change
170
170
  attrs.each { |k,v| self.send("#{k}=", v) }
@@ -1,3 +1,3 @@
1
1
  module Amfetamine
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -43,7 +43,7 @@ describe Amfetamine::Base do
43
43
  response.should be_cached
44
44
  end
45
45
  end
46
-
46
+
47
47
  it "should return nil if object not found" do
48
48
  lambda {
49
49
  Dummy.prevent_external_connections! do |r|
@@ -69,7 +69,7 @@ describe Amfetamine::Base do
69
69
  dummies.should include(dummy2)
70
70
  dummies.length.should eq(2)
71
71
  end
72
-
72
+
73
73
  it "should return empty array if objects are not present" do
74
74
  Dummy.prevent_external_connections! do |r|
75
75
  r.get(:code => 200) {[]}
@@ -104,20 +104,27 @@ describe Amfetamine::Base do
104
104
  end
105
105
 
106
106
  context "#update" do
107
- before(:each) do
107
+ before do
108
108
  dummy.send(:notsaved=, false)
109
109
  end
110
110
 
111
111
  it "should update if response is succesful" do
112
112
  Dummy.prevent_external_connections! do |r|
113
113
  r.put {}
114
-
115
114
  dummy.update_attributes({:title => 'zomg'})
116
115
  end
117
-
118
116
  dummy.should_not be_new
119
117
  dummy.title.should eq('zomg')
120
- dummy.should be_cached
118
+ dummy.should be_cached
119
+ end
120
+
121
+ it "should return true for successful updates even with disabled caching" do
122
+ Dummy.disable_caching = true
123
+ Dummy.prevent_external_connections! do |r|
124
+ r.put {}
125
+ dummy.update_attributes({ :title => 'zomg' }).should be_true
126
+ end
127
+ Dummy.disable_caching = false
121
128
  end
122
129
 
123
130
  it "should show errors if response is not succesful" do
@@ -222,5 +229,5 @@ describe Amfetamine::Base do
222
229
  end
223
230
 
224
231
  end
225
-
232
+
226
233
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amfetamine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-12 00:00:00.000000000 Z
13
+ date: 2012-09-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -333,7 +333,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
333
333
  version: '0'
334
334
  segments:
335
335
  - 0
336
- hash: 764523330913255459
336
+ hash: 2740467481176466622
337
337
  required_rubygems_version: !ruby/object:Gem::Requirement
338
338
  none: false
339
339
  requirements:
@@ -342,7 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
342
342
  version: '0'
343
343
  segments:
344
344
  - 0
345
- hash: 764523330913255459
345
+ hash: 2740467481176466622
346
346
  requirements: []
347
347
  rubyforge_project: amfetamine
348
348
  rubygems_version: 1.8.24