reactive_resource 0.6.0 → 0.6.1

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.
@@ -55,12 +55,13 @@ module ReactiveResource
55
55
  # address.lawyer_id
56
56
  define_method("#{attribute}_id") do
57
57
  prefix_options["#{attribute}_id".intern]
58
+ super()
58
59
  end
59
60
 
60
61
  # address.lawyer_id = 3
61
62
  define_method("#{attribute}_id=") do |value|
62
63
  prefix_options["#{attribute}_id".intern] = value
63
- attributes["#{attribute}_id".intern] = value
64
+ super(value)
64
65
  end
65
66
 
66
67
  # address.lawyer
@@ -89,13 +89,14 @@ module ReactiveResource
89
89
  # be in the URL anyway), so we'll try to inject them based on the
90
90
  # attributes of the object we just used.
91
91
  def load(attributes)
92
+ attributes = attributes.stringify_keys
92
93
  self.class.belongs_to_with_parents.each do |belongs_to_param|
93
- attributes["#{belongs_to_param}_id".intern] ||= prefix_options["#{belongs_to_param}_id".intern]
94
+ attributes["#{belongs_to_param}_id"] ||= prefix_options["#{belongs_to_param}_id".intern]
94
95
 
95
96
  # also set prefix attributes as real attributes. Otherwise,
96
97
  # belongs_to attributes will be stripped out of the response
97
98
  # even if we aren't actually using the association.
98
- @attributes["#{belongs_to_param}_id".intern] = attributes["#{belongs_to_param}_id".intern]
99
+ @attributes["#{belongs_to_param}_id"] = attributes["#{belongs_to_param}_id"]
99
100
  end
100
101
  super(attributes)
101
102
  end
@@ -1,4 +1,4 @@
1
1
  module ReactiveResource
2
2
  # The current version of ReactiveResource
3
- VERSION = "0.6.0"
3
+ VERSION = "0.6.1"
4
4
  end
@@ -175,11 +175,33 @@ class ReactiveResource::BaseTest < Test::Unit::TestCase
175
175
  assert_requested(:post, "https://api.avvo.com/api/1/lawyers/1/lawyer_posts.json")
176
176
  end
177
177
 
178
+ should "treat returned prefix parameters as regular parameters" do
179
+ stub_request(:get, "https://api.avvo.com/api/1/lawyers/1/lawyer_posts.json").
180
+ to_return(:body =>[{"id" => 1, "post_id" => 2}].to_json)
181
+ stub_request(:put, "https://api.avvo.com/api/1/lawyers/1/lawyer_posts/1.json").
182
+ with(:body => {"lawyer_post" => {"id" => 1, "post_id" => 3}})
183
+
184
+ @object = ReactiveResource::LawyerPost.find(:all, :params => {:lawyer_id => 1}).first
185
+ assert_not_nil @object.post_id
186
+
187
+ @object.post_id = 3
188
+ @object.save
189
+
190
+ assert_requested(:put, "https://api.avvo.com/api/1/lawyers/1/lawyer_posts/1.json")
191
+ end
192
+
178
193
  should "set the attributes correctly when it's created" do
179
194
  @object = ReactiveResource::LawyerPost.new(:lawyer_id => 1, :post_id => 2)
180
195
  assert_not_nil @object.attributes[:post_id]
181
196
  assert_not_nil @object.attributes[:lawyer_id]
182
197
  end
198
+
199
+ should "set the attributes correctly when it's created with strings" do
200
+ @object = ReactiveResource::LawyerPost.new("lawyer_id" => 1, "post_id" => 2)
201
+ assert_not_nil @object.post_id
202
+ assert_not_nil @object.attributes["post_id"]
203
+ assert_not_nil @object.attributes[:lawyer_id]
204
+ end
183
205
  end
184
206
 
185
207
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 0
9
- version: 0.6.0
8
+ - 1
9
+ version: 0.6.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Justin Weiss
@@ -14,11 +14,12 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-04-13 00:00:00 -07:00
17
+ date: 2011-04-14 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activeresource
22
+ prerelease: false
22
23
  requirement: &id001 !ruby/object:Gem::Requirement
23
24
  none: false
24
25
  requirements:
@@ -30,10 +31,10 @@ dependencies:
30
31
  - 10
31
32
  version: 2.3.10
32
33
  type: :runtime
33
- prerelease: false
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: shoulda
37
+ prerelease: false
37
38
  requirement: &id002 !ruby/object:Gem::Requirement
38
39
  none: false
39
40
  requirements:
@@ -45,10 +46,10 @@ dependencies:
45
46
  - 3
46
47
  version: 2.11.3
47
48
  type: :development
48
- prerelease: false
49
49
  version_requirements: *id002
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: webmock
52
+ prerelease: false
52
53
  requirement: &id003 !ruby/object:Gem::Requirement
53
54
  none: false
54
55
  requirements:
@@ -60,7 +61,6 @@ dependencies:
60
61
  - 1
61
62
  version: 1.6.1
62
63
  type: :development
63
- prerelease: false
64
64
  version_requirements: *id003
65
65
  description: ActiveRecord-like associations for ActiveResource
66
66
  email:
@@ -105,7 +105,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - ">="
107
107
  - !ruby/object:Gem::Version
108
- hash: -2570327779021755250
109
108
  segments:
110
109
  - 0
111
110
  version: "0"
@@ -114,7 +113,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
113
  requirements:
115
114
  - - ">="
116
115
  - !ruby/object:Gem::Version
117
- hash: -2570327779021755250
118
116
  segments:
119
117
  - 0
120
118
  version: "0"