dupe 0.5.3 → 0.6.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/README.rdoc +1 -31
- data/lib/dupe/active_resource_extensions.rb +11 -9
- data/lib/dupe.rb +3 -0
- data/spec/lib_specs/active_resource_extensions_spec.rb +34 -7
- metadata +13 -11
data/README.rdoc
CHANGED
|
@@ -15,39 +15,9 @@ If you want to install this for use in something other than a rails project, sim
|
|
|
15
15
|
|
|
16
16
|
# gem install dupe
|
|
17
17
|
|
|
18
|
-
If you're going to use this in a rails (2.3.*) project, add this to your cucumber.rb environment (config/environments/cucumber.rb)
|
|
19
|
-
|
|
20
|
-
config.gem 'dupe'
|
|
21
|
-
|
|
22
|
-
Then run this rake task to install the gem:
|
|
23
|
-
|
|
24
|
-
# rake gems:install RAILS_ENV=cucumber
|
|
25
|
-
|
|
26
|
-
Lastly, from your rails project root, run:
|
|
27
|
-
|
|
28
|
-
# script/generate dupe
|
|
29
|
-
|
|
30
|
-
That last command will create the following directories:
|
|
31
|
-
|
|
32
|
-
- RAILS_ROOT/features/dupe
|
|
33
|
-
- RAILS_ROOT/features/dupe/definitions
|
|
34
|
-
- RAILS_ROOT/features/dupe/custom_mocks
|
|
35
|
-
|
|
36
|
-
It will also place example Dupe definitions in RAILS_ROOT/features/dupe/definitions/definitions.rb as well as example custom mocks in RAILS_ROOT/features/dupe/custom_mocks/custom_mocks.rb
|
|
37
|
-
|
|
38
|
-
Lastly, it will add a load_dupe.rb file (that loads up the definitions and custom mocks) to RAILS_ROOT/features/support/load_dupe.rb
|
|
39
|
-
|
|
40
18
|
== Rails 3
|
|
41
19
|
|
|
42
|
-
|
|
43
|
-
If you need Dupe for a rails 3 project, give it a whirl. Simply add something like the following to your bundler file:
|
|
44
|
-
|
|
45
|
-
gem 'dupe', :git => 'git://github.com/moonmaster9000/dupe.git', :branch => 'rails3'
|
|
46
|
-
|
|
47
|
-
"script/generate dupe" doesn't yet work in Rails3.
|
|
48
|
-
|
|
49
|
-
Once Rails3 goes production, we'll be merging this branch into master and only supporting Rails3 from that point on. (Of course, if
|
|
50
|
-
anyone at that point still has a need to use Dupe in a rails 2.3 project, they will still be able to use one of the older versions).
|
|
20
|
+
Dupe versions 0.6.0 and greater only work with Rails 3 / ActiveResource 3. If you're working on a Rails 2.* project, use Dupe version 0.5.3.
|
|
51
21
|
|
|
52
22
|
= Tutorial
|
|
53
23
|
|
|
@@ -8,7 +8,7 @@ module ActiveResource #:nodoc:
|
|
|
8
8
|
class Connection #:nodoc:
|
|
9
9
|
def get(path, headers = {}) #:nodoc:
|
|
10
10
|
begin
|
|
11
|
-
response = request(:get, path, build_request_headers(headers, :get))
|
|
11
|
+
response = request(:get, path, build_request_headers(headers, :get, self.site.merge(path)))
|
|
12
12
|
|
|
13
13
|
# if the request threw an exception
|
|
14
14
|
rescue
|
|
@@ -16,7 +16,7 @@ module ActiveResource #:nodoc:
|
|
|
16
16
|
ActiveResource::HttpMock.respond_to do |mock|
|
|
17
17
|
mock.get(path, {}, mocked_response)
|
|
18
18
|
end
|
|
19
|
-
response = request(:get, path, build_request_headers(headers, :get))
|
|
19
|
+
response = request(:get, path, build_request_headers(headers, :get, self.site.merge(path)))
|
|
20
20
|
ActiveResource::HttpMock.delete_mock(:get, path)
|
|
21
21
|
end
|
|
22
22
|
format.decode(response.body)
|
|
@@ -24,7 +24,7 @@ module ActiveResource #:nodoc:
|
|
|
24
24
|
|
|
25
25
|
def post(path, body = '', headers = {}) #:nodoc:
|
|
26
26
|
begin
|
|
27
|
-
response = request(:post, path, body.to_s, build_request_headers(headers, :post))
|
|
27
|
+
response = request(:post, path, body.to_s, build_request_headers(headers, :post, self.site.merge(path)))
|
|
28
28
|
|
|
29
29
|
# if the request threw an exception
|
|
30
30
|
rescue
|
|
@@ -45,7 +45,7 @@ module ActiveResource #:nodoc:
|
|
|
45
45
|
mock.post(path, {}, mocked_response, 201, "Location" => new_path)
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
|
-
response = request(:post, path, body.to_s, build_request_headers(headers, :post))
|
|
48
|
+
response = request(:post, path, body.to_s, build_request_headers(headers, :post, self.site.merge(path)))
|
|
49
49
|
ActiveResource::HttpMock.delete_mock(:post, path)
|
|
50
50
|
end
|
|
51
51
|
response
|
|
@@ -53,12 +53,14 @@ module ActiveResource #:nodoc:
|
|
|
53
53
|
|
|
54
54
|
def put(path, body = '', headers = {}) #:nodoc:
|
|
55
55
|
begin
|
|
56
|
-
response = request(:put, path, body.to_s, build_request_headers(headers, :put))
|
|
56
|
+
response = request(:put, path, body.to_s, build_request_headers(headers, :put, self.site.merge(path)))
|
|
57
57
|
|
|
58
58
|
# if the request threw an exception
|
|
59
59
|
rescue
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
unless body.blank?
|
|
61
|
+
resource_hash = Hash.from_xml(body)
|
|
62
|
+
resource_hash = resource_hash[resource_hash.keys.first]
|
|
63
|
+
end
|
|
62
64
|
resource_hash = {} unless resource_hash.kind_of?(Hash)
|
|
63
65
|
resource_hash.symbolize_keys!
|
|
64
66
|
|
|
@@ -76,7 +78,7 @@ module ActiveResource #:nodoc:
|
|
|
76
78
|
mock.put(path, {}, mocked_response, 204)
|
|
77
79
|
end
|
|
78
80
|
end
|
|
79
|
-
response = request(:put, path, body.to_s, build_request_headers(headers, :put))
|
|
81
|
+
response = request(:put, path, body.to_s, build_request_headers(headers, :put, self.site.merge(path)))
|
|
80
82
|
ActiveResource::HttpMock.delete_mock(:put, path)
|
|
81
83
|
end
|
|
82
84
|
response
|
|
@@ -88,7 +90,7 @@ module ActiveResource #:nodoc:
|
|
|
88
90
|
ActiveResource::HttpMock.respond_to do |mock|
|
|
89
91
|
mock.delete(path, {}, nil, 200)
|
|
90
92
|
end
|
|
91
|
-
response = request(:delete, path, build_request_headers(headers, :delete))
|
|
93
|
+
response = request(:delete, path, build_request_headers(headers, :delete, self.site.merge(path)))
|
|
92
94
|
|
|
93
95
|
ActiveResource::HttpMock.delete_mock(:delete, path)
|
|
94
96
|
response
|
data/lib/dupe.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
require 'dupe/hash_pruner'
|
|
2
|
+
require 'active_support/inflector'
|
|
3
|
+
require 'active_support/core_ext'
|
|
2
4
|
require 'active_resource'
|
|
3
5
|
require 'active_resource/http_mock'
|
|
6
|
+
require 'active_resource/version'
|
|
4
7
|
require 'dupe/singular_plural_detection'
|
|
5
8
|
require 'dupe/symbol'
|
|
6
9
|
require 'dupe/string'
|
|
@@ -9,7 +9,7 @@ describe ActiveResource::Connection do
|
|
|
9
9
|
before do
|
|
10
10
|
@book = Dupe.create :book, :title => 'Rooby', :label => 'rooby'
|
|
11
11
|
class Book < ActiveResource::Base
|
|
12
|
-
self.site = ''
|
|
12
|
+
self.site = 'http://www.example.com'
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
@@ -32,7 +32,7 @@ describe ActiveResource::Connection do
|
|
|
32
32
|
@book = Dupe.create :book, :label => 'rooby', :title => 'Rooby'
|
|
33
33
|
@book.delete(:id)
|
|
34
34
|
class Book < ActiveResource::Base
|
|
35
|
-
self.site = ''
|
|
35
|
+
self.site = 'http://www.example.com'
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
@@ -56,7 +56,7 @@ describe ActiveResource::Connection do
|
|
|
56
56
|
|
|
57
57
|
b = Book.create
|
|
58
58
|
b.new?.should be_true
|
|
59
|
-
b.errors.
|
|
59
|
+
b.errors.should_not be_empty
|
|
60
60
|
b = Book.create(:title => "hello")
|
|
61
61
|
b.new?.should be_false
|
|
62
62
|
b.errors.should be_empty
|
|
@@ -67,16 +67,43 @@ describe ActiveResource::Connection do
|
|
|
67
67
|
before do
|
|
68
68
|
@book = Dupe.create :book, :label => 'rooby', :title => 'Rooby'
|
|
69
69
|
class Book < ActiveResource::Base
|
|
70
|
-
self.site = ''
|
|
70
|
+
self.site = 'http://www.example.com'
|
|
71
71
|
end
|
|
72
72
|
@ar_book = Book.find(1)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it "should pass a request off to the Dupe network if the original request failed" do
|
|
76
|
-
Dupe.network.should_receive(:request).with(:put, '/books/1.xml', Hash.from_xml(@book.merge(:title => "Rails!").to_xml(:root => 'book'))["book"].symbolize_keys!).once
|
|
76
|
+
Dupe.network.should_receive(:request).with(:put, '/books/1.xml', Hash.from_xml(@book.merge(:title => "Rails!").to_xml(:root => 'book'))["book"].symbolize_keys!).once.and_return([nil, '/books/1.xml'])
|
|
77
77
|
@ar_book.title = 'Rails!'
|
|
78
78
|
@ar_book.save
|
|
79
79
|
end
|
|
80
|
+
|
|
81
|
+
context "put methods that return HTTP 204" do
|
|
82
|
+
before(:each) do
|
|
83
|
+
class ExpirableBook < ActiveResource::Base
|
|
84
|
+
self.site = 'http://www.example.com'
|
|
85
|
+
attr_accessor :state
|
|
86
|
+
|
|
87
|
+
def expire_copyrights!
|
|
88
|
+
put(:expire)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
Put %r{/expirable_books/(\d)+/expire.xml} do |id, body|
|
|
93
|
+
Dupe.find(:expirable_book) { |eb| eb.id == id.to_i }.tap { |book|
|
|
94
|
+
book.state = 'expired'
|
|
95
|
+
}
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
@e = Dupe.create :expirable_book, :title => 'Impermanence', :state => 'active'
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "should handle no-content responses" do
|
|
102
|
+
response = ExpirableBook.find(@e.id).expire_copyrights!
|
|
103
|
+
response.body.should be_blank
|
|
104
|
+
response.code.to_s.should == "204"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
80
107
|
|
|
81
108
|
it "should parse the xml and turn the result into active resource objects" do
|
|
82
109
|
@book.title.should == "Rooby"
|
|
@@ -99,7 +126,7 @@ describe ActiveResource::Connection do
|
|
|
99
126
|
|
|
100
127
|
@ar_book.title = nil
|
|
101
128
|
@ar_book.save.should == false
|
|
102
|
-
@ar_book.errors.
|
|
129
|
+
@ar_book.errors[:base].should_not be_empty
|
|
103
130
|
|
|
104
131
|
@ar_book.title = "Rails!"
|
|
105
132
|
@ar_book.save.should == true
|
|
@@ -113,7 +140,7 @@ describe ActiveResource::Connection do
|
|
|
113
140
|
before do
|
|
114
141
|
@book = Dupe.create :book, :label => 'rooby', :title => 'Rooby'
|
|
115
142
|
class Book < ActiveResource::Base
|
|
116
|
-
self.site = ''
|
|
143
|
+
self.site = 'http://www.example.com'
|
|
117
144
|
end
|
|
118
145
|
@ar_book = Book.find(1)
|
|
119
146
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dupe
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 7
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
version: 0.
|
|
8
|
+
- 6
|
|
9
|
+
- 0
|
|
10
|
+
version: 0.6.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Matt Parker
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date:
|
|
18
|
+
date: 2011-01-08 00:00:00 -05:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -24,13 +24,15 @@ dependencies:
|
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
25
|
none: false
|
|
26
26
|
requirements:
|
|
27
|
-
- -
|
|
27
|
+
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
hash:
|
|
29
|
+
hash: -1848230022
|
|
30
30
|
segments:
|
|
31
|
-
- 2
|
|
32
31
|
- 3
|
|
33
|
-
|
|
32
|
+
- 0
|
|
33
|
+
- 0
|
|
34
|
+
- beta2
|
|
35
|
+
version: 3.0.0.beta2
|
|
34
36
|
type: :runtime
|
|
35
37
|
version_requirements: *id001
|
|
36
38
|
description: |-
|
|
@@ -92,8 +94,8 @@ homepage: http://github.com/moonmaster9000/dupe
|
|
|
92
94
|
licenses: []
|
|
93
95
|
|
|
94
96
|
post_install_message:
|
|
95
|
-
rdoc_options:
|
|
96
|
-
|
|
97
|
+
rdoc_options: []
|
|
98
|
+
|
|
97
99
|
require_paths:
|
|
98
100
|
- lib
|
|
99
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|