activeresource-response 0.5.3 → 1.0.0

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/.travis.yml CHANGED
@@ -1,12 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
- - 1.9.2
5
- - jruby-18mode
6
4
  - jruby-19mode
7
- - rbx-18mode
8
5
  - rbx-19mode
9
- - 1.8.7
10
- - ree
11
6
  - ruby-head
12
7
  - jruby-head
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{This gem adds possibility to access http response object from result of ActiveResource::Base find method }
14
14
 
15
15
 
16
- s.add_dependency('activeresource', '>= 3.0')
16
+ s.add_dependency('activeresource', '>= 4.0.0')
17
17
 
18
18
  s.add_dependency "jruby-openssl" if RUBY_PLATFORM == "java"
19
19
  s.add_development_dependency "test-unit"
@@ -31,7 +31,7 @@ module ActiveResourceResponse
31
31
  def get(custom_method_name, options = {})
32
32
  result = self.origin_get(custom_method_name, options)
33
33
  if self.respond_to? :http_response_method
34
- result = self.merge_response_to_result(result)
34
+ result = self.wrap_result(result)
35
35
  end
36
36
  result
37
37
  end
@@ -41,7 +41,7 @@ module ActiveResourceResponse
41
41
  def get(custom_method_name, options = {})
42
42
  result = super(custom_method_name, options)
43
43
  if self.class.respond_to? :http_response_method
44
- result = self.class.merge_response_to_result(result)
44
+ result = self.class.wrap_result(result)
45
45
  end
46
46
  result
47
47
  end
@@ -20,6 +20,7 @@
20
20
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
+ require 'delegate'
23
24
  module ActiveResourceResponse
24
25
 
25
26
  module ResponseMethod
@@ -36,34 +37,33 @@ module ActiveResourceResponse
36
37
 
37
38
  def add_response_method(method_name = :http_response)
38
39
  class_attribute :http_response_method
39
- self.http_response_method = method_name
40
+ self.http_response_method = method_name
40
41
  class << self
41
42
  alias :find_without_http_response :find
42
43
 
43
44
  def find(*arguments)
44
45
  result = find_without_http_response(*arguments)
45
- self.merge_response_to_result(result)
46
+ self.wrap_result(result)
46
47
  end
47
48
  end unless methods.map(&:to_sym).include?(:find_without_http_response)
48
49
  end
49
-
50
+
50
51
  def remove_response_method
51
- class << self
52
- undef :find
53
- alias :find :find_without_http_response
54
- undef :find_without_http_response
55
- undef :http_response_method
56
- undef :http_response_method=
57
- end
52
+ class << self
53
+ undef :find
54
+ alias :find :find_without_http_response
55
+ undef :find_without_http_response
56
+ undef :http_response_method
57
+ undef :http_response_method=
58
+ end
58
59
  end
59
60
 
60
- def merge_response_to_result(result)
61
- begin
62
- result.instance_variable_set(:@http_response, connection.http_response)
63
- (class << result; self; end).send(:define_method, self.http_response_method) do
64
- @http_response
65
- end
66
- rescue StandardError
61
+ def wrap_result(result)
62
+
63
+ result = SimpleDelegator.new(result)
64
+ result.instance_variable_set(:@http_response, connection.http_response)
65
+ result.singleton_class.send(:define_method, self.http_response_method) do
66
+ @http_response
67
67
  end
68
68
  result
69
69
  end
@@ -23,6 +23,6 @@
23
23
 
24
24
  module ActiveResourceResponse
25
25
  module Version
26
- VERSION = "0.5.3"
26
+ VERSION = "1.0.0"
27
27
  end
28
28
  end
@@ -33,12 +33,13 @@ require "fixtures/city"
33
33
  require "fixtures/region"
34
34
  require "fixtures/street"
35
35
  require "active_resource_response/http_mock"
36
+
36
37
  class ActiveResourceResponseTest < Test::Unit::TestCase
37
38
 
38
39
 
39
40
  def setup
40
41
  @country = {:country => {:id => 1, :name => "Ukraine", :iso=>"UA"}}
41
- @country_create_error = {"errors"=>{:base => ["Country exists"]}}
42
+ @country_create_error = {:errors => {:base => ["country exists"]}}
42
43
  @city = {:city => {:id => 1, :name => "Odessa", :population => 2500000}}
43
44
  @region = {:region => {:id => 1, :name => "Odessa region", :population => 4500000}}
44
45
  @street = {:street => {:id => 1, :name => "Deribasovskaya", :population => 2300}}
@@ -51,7 +52,7 @@ class ActiveResourceResponseTest < Test::Unit::TestCase
51
52
  mock.get "/regions/cities.json", {}, [@city].to_json, 200, {"X-total"=>'2'}
52
53
  mock.get "/countries/1.json", {}, @country.to_json, 200, {"X-total"=>'1', 'Set-Cookie'=>['path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT, foo=bar, bar=foo']}
53
54
  mock.get "/countries/1/population.json", {}, {:count => 45000000}.to_json, 200, {"X-total"=>'1'}
54
- mock.post "/countries.json", {}, @country.to_json, 422, {"X-total"=>'1'}
55
+ mock.post "/countries.json", {}, @country_create_error.to_json, 422, {"X-total"=>'1'}
55
56
  mock.get "/countries/1/cities.json", {}, [@city].to_json, 200, {"X-total"=>'1'}
56
57
  mock.get "/regions/1/cities.json", {}, [@city].to_json, 200, {"X-total"=>'1'}
57
58
  mock.get "/cities/1/population.json", {}, {:count => 2500000}.to_json, 200, {"X-total"=>'1'}
@@ -87,7 +88,13 @@ class ActiveResourceResponseTest < Test::Unit::TestCase
87
88
  assert cities.respond_to?(:http_response)
88
89
  assert_equal cities.http_response.headers[:x_total].to_i, 2
89
90
  count = Country.find(1).get("population")
90
- assert_equal count.to_i, 45000000
91
+
92
+ #immutable objects doing good
93
+ some_numeric = 45000000
94
+ assert_equal count.to_i, some_numeric
95
+ assert count.respond_to?(:http)
96
+ assert !some_numeric.respond_to?(:http)
97
+
91
98
  assert_equal Country.connection.http_response.headers[:x_total].to_i, 1
92
99
  assert_equal Country.http_response.headers[:x_total].to_i, 1
93
100
  cities = Country.find(1).get("cities")
@@ -107,6 +114,7 @@ class ActiveResourceResponseTest < Test::Unit::TestCase
107
114
  assert_kind_of City, cities.first
108
115
  count = cities.first.get("population")
109
116
  assert_equal count.to_i, 2500000
117
+
110
118
  end
111
119
 
112
120
  def test_get_headers_from_find
@@ -128,6 +136,8 @@ class ActiveResourceResponseTest < Test::Unit::TestCase
128
136
  country = Country.create(@country[:country])
129
137
  assert_equal Country.http_response.headers[:x_total].to_i, 1
130
138
  assert_equal Country.http_response.code, 422
139
+ assert_equal country.errors.full_messages.count ,1
140
+ assert_equal country.errors.count ,1
131
141
  end
132
142
 
133
143
  def test_remove_method
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeresource-response
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-11 00:00:00.000000000 Z
12
+ date: 2013-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activeresource
16
- requirement: &70124761807700 !ruby/object:Gem::Requirement
16
+ requirement: &70196300726880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '3.0'
21
+ version: 4.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70124761807700
24
+ version_requirements: *70196300726880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: test-unit
27
- requirement: &70124761805760 !ruby/object:Gem::Requirement
27
+ requirement: &70196300725540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70124761805760
35
+ version_requirements: *70196300725540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70124758023700 !ruby/object:Gem::Requirement
38
+ requirement: &70196300738620 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70124758023700
46
+ version_requirements: *70196300738620
47
47
  description: ! 'This gem adds possibility to access http response object from result
48
48
  of ActiveResource::Base find method '
49
49
  email: