dupe 1.0.0 → 1.0.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.
| 
         @@ -19,22 +19,24 @@ module ActiveResource #:nodoc: 
     | 
|
| 
       19 
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 
     | 
    
         
            +
             
     | 
| 
       23 
23 
     | 
    
         
             
                  if ActiveResource::VERSION::MAJOR == 3 && ActiveResource::VERSION::MINOR >= 1
         
     | 
| 
       24 
24 
     | 
    
         
             
                    response
         
     | 
| 
       25 
25 
     | 
    
         
             
                  else
         
     | 
| 
       26 
26 
     | 
    
         
             
                    format.decode(response.body)
         
     | 
| 
       27 
27 
     | 
    
         
             
                  end
         
     | 
| 
       28 
28 
     | 
    
         
             
                end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
       30 
30 
     | 
    
         
             
                def post(path, body = '', headers = {}) #:nodoc:
         
     | 
| 
       31 
31 
     | 
    
         
             
                  begin
         
     | 
| 
       32 
32 
     | 
    
         
             
                    response = request(:post, path, body.to_s, build_request_headers(headers, :post, self.site.merge(path)))
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
       34 
34 
     | 
    
         
             
                  # if the request threw an exception
         
     | 
| 
       35 
35 
     | 
    
         
             
                  rescue
         
     | 
| 
       36 
     | 
    
         
            -
                     
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
                    unless body.blank?
         
     | 
| 
      
 37 
     | 
    
         
            +
                      resource_hash = Hash.from_xml(body)
         
     | 
| 
      
 38 
     | 
    
         
            +
                      resource_hash = resource_hash[resource_hash.keys.first]
         
     | 
| 
      
 39 
     | 
    
         
            +
                    end
         
     | 
| 
       38 
40 
     | 
    
         
             
                    resource_hash = {} unless resource_hash.kind_of?(Hash)
         
     | 
| 
       39 
41 
     | 
    
         
             
                    begin
         
     | 
| 
       40 
42 
     | 
    
         
             
                      mocked_response, new_path = Dupe.network.request(:post, path, resource_hash)
         
     | 
| 
         @@ -55,11 +57,11 @@ module ActiveResource #:nodoc: 
     | 
|
| 
       55 
57 
     | 
    
         
             
                  end
         
     | 
| 
       56 
58 
     | 
    
         
             
                  response
         
     | 
| 
       57 
59 
     | 
    
         
             
                end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
       59 
61 
     | 
    
         
             
                def put(path, body = '', headers = {}) #:nodoc:
         
     | 
| 
       60 
62 
     | 
    
         
             
                  begin
         
     | 
| 
       61 
63 
     | 
    
         
             
                    response = request(:put, path, body.to_s, build_request_headers(headers, :put, self.site.merge(path)))
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
       63 
65 
     | 
    
         
             
                  # if the request threw an exception
         
     | 
| 
       64 
66 
     | 
    
         
             
                  rescue
         
     | 
| 
       65 
67 
     | 
    
         
             
                    unless body.blank?
         
     | 
| 
         @@ -96,7 +98,7 @@ module ActiveResource #:nodoc: 
     | 
|
| 
       96 
98 
     | 
    
         
             
                    mock.delete(path, {}, nil, 200)
         
     | 
| 
       97 
99 
     | 
    
         
             
                  end
         
     | 
| 
       98 
100 
     | 
    
         
             
                  response = request(:delete, path, build_request_headers(headers, :delete, self.site.merge(path)))
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
       100 
102 
     | 
    
         
             
                  ActiveResource::HttpMock.delete_mock(:delete, path)
         
     | 
| 
       101 
103 
     | 
    
         
             
                  response
         
     | 
| 
       102 
104 
     | 
    
         
             
                end
         
     | 
| 
         @@ -1,10 +1,10 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            describe ActiveResource::Connection do 
     | 
| 
      
 3 
     | 
    
         
            +
            describe ActiveResource::Connection do
         
     | 
| 
       4 
4 
     | 
    
         
             
              before do
         
     | 
| 
       5 
5 
     | 
    
         
             
                Dupe.reset
         
     | 
| 
       6 
6 
     | 
    
         
             
              end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       8 
8 
     | 
    
         
             
              describe "#get" do
         
     | 
| 
       9 
9 
     | 
    
         
             
                before do
         
     | 
| 
       10 
10 
     | 
    
         
             
                  @book = Dupe.create :book, :title => 'Rooby', :label => 'rooby'
         
     | 
| 
         @@ -13,12 +13,12 @@ describe ActiveResource::Connection do 
     | 
|
| 
       13 
13 
     | 
    
         
             
                    self.format = :xml
         
     | 
| 
       14 
14 
     | 
    
         
             
                  end
         
     | 
| 
       15 
15 
     | 
    
         
             
                end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                it "should pass a request off to the Dupe network if the original request failed" do 
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                it "should pass a request off to the Dupe network if the original request failed" do
         
     | 
| 
       18 
18 
     | 
    
         
             
                  Dupe.network.should_receive(:request).with(:get, '/books.xml').once.and_return(Dupe.find(:books).to_xml(:root => 'books'))
         
     | 
| 
       19 
19 
     | 
    
         
             
                  books = Book.find(:all)
         
     | 
| 
       20 
20 
     | 
    
         
             
                end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
       22 
22 
     | 
    
         
             
                it "should parse the xml and turn the result into active resource objects" do
         
     | 
| 
       23 
23 
     | 
    
         
             
                  books = Book.find(:all)
         
     | 
| 
       24 
24 
     | 
    
         
             
                  books.length.should == 1
         
     | 
| 
         @@ -27,7 +27,7 @@ describe ActiveResource::Connection do 
     | 
|
| 
       27 
27 
     | 
    
         
             
                  books.first.label.should == 'rooby'
         
     | 
| 
       28 
28 
     | 
    
         
             
                end
         
     | 
| 
       29 
29 
     | 
    
         
             
              end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
       31 
31 
     | 
    
         
             
              describe "#post" do
         
     | 
| 
       32 
32 
     | 
    
         
             
                before do
         
     | 
| 
       33 
33 
     | 
    
         
             
                  @book = Dupe.create :book, :label => 'rooby', :title => 'Rooby'
         
     | 
| 
         @@ -36,25 +36,25 @@ describe ActiveResource::Connection do 
     | 
|
| 
       36 
36 
     | 
    
         
             
                    self.site = 'http://www.example.com'
         
     | 
| 
       37 
37 
     | 
    
         
             
                  end
         
     | 
| 
       38 
38 
     | 
    
         
             
                end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
       40 
40 
     | 
    
         
             
                it "should pass a request off to the Dupe network if the original request failed" do
         
     | 
| 
       41 
41 
     | 
    
         
             
                  Dupe.network.should_receive(:request).with(:post, '/books.xml', Hash.from_xml(@book.to_xml(:root => 'book'))["book"] ).once
         
     | 
| 
       42 
42 
     | 
    
         
             
                  book = Book.create({:label => 'rooby', :title => 'Rooby'})
         
     | 
| 
       43 
43 
     | 
    
         
             
                end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
       45 
45 
     | 
    
         
             
                it "should parse the xml and turn the result into active resource objects" do
         
     | 
| 
       46 
46 
     | 
    
         
             
                  book = Book.create({:label => 'rooby', :title => 'Rooby'})
         
     | 
| 
       47 
47 
     | 
    
         
             
                  book.id.should == 2
         
     | 
| 
       48 
48 
     | 
    
         
             
                  book.title.should == 'Rooby'
         
     | 
| 
       49 
49 
     | 
    
         
             
                  book.label.should == 'rooby'
         
     | 
| 
       50 
50 
     | 
    
         
             
                end
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
       52 
52 
     | 
    
         
             
                it "should make ActiveResource throw an unprocessable entity exception if our Post mock throws a Dupe::UnprocessableEntity exception" do
         
     | 
| 
       53 
53 
     | 
    
         
             
                  Post %r{/books\.xml} do |post_data|
         
     | 
| 
       54 
54 
     | 
    
         
             
                    raise Dupe::UnprocessableEntity.new(:title => "must be present.") unless post_data["title"]
         
     | 
| 
       55 
55 
     | 
    
         
             
                    Dupe.create :book, post_data
         
     | 
| 
       56 
56 
     | 
    
         
             
                  end
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
       58 
58 
     | 
    
         
             
                  b = Book.create
         
     | 
| 
       59 
59 
     | 
    
         
             
                  b.new?.should be_true
         
     | 
| 
       60 
60 
     | 
    
         
             
                  b.errors.should_not be_empty
         
     | 
| 
         @@ -62,6 +62,24 @@ describe ActiveResource::Connection do 
     | 
|
| 
       62 
62 
     | 
    
         
             
                  b.new?.should be_false
         
     | 
| 
       63 
63 
     | 
    
         
             
                  b.errors.should be_empty
         
     | 
| 
       64 
64 
     | 
    
         
             
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                it "should handle request with blank body" do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  class SubscribableBook < ActiveResource::Base
         
     | 
| 
      
 68 
     | 
    
         
            +
                    self.site = 'http://www.example.com'
         
     | 
| 
      
 69 
     | 
    
         
            +
                    self.format = :xml
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                    def self.send_update_emails
         
     | 
| 
      
 72 
     | 
    
         
            +
                      post(:send_update_emails)
         
     | 
| 
      
 73 
     | 
    
         
            +
                    end
         
     | 
| 
      
 74 
     | 
    
         
            +
                  end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                  Post %r{/subscribable_books/send_update_emails\.xml} do |post_data|
         
     | 
| 
      
 77 
     | 
    
         
            +
                    Dupe.create :email, post_data
         
     | 
| 
      
 78 
     | 
    
         
            +
                  end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                  response = SubscribableBook.send_update_emails
         
     | 
| 
      
 81 
     | 
    
         
            +
                  response.code.should == 201
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
       65 
83 
     | 
    
         
             
              end
         
     | 
| 
       66 
84 
     | 
    
         | 
| 
       67 
85 
     | 
    
         
             
              describe "#put" do
         
     | 
| 
         @@ -72,7 +90,7 @@ describe ActiveResource::Connection do 
     | 
|
| 
       72 
90 
     | 
    
         
             
                  end
         
     | 
| 
       73 
91 
     | 
    
         
             
                  @ar_book = Book.find(1)
         
     | 
| 
       74 
92 
     | 
    
         
             
                end
         
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
       76 
94 
     | 
    
         
             
                it "should pass a request off to the Dupe network if the original request failed" do
         
     | 
| 
       77 
95 
     | 
    
         
             
                  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'])
         
     | 
| 
       78 
96 
     | 
    
         
             
                  @ar_book.title = 'Rails!'
         
     | 
| 
         @@ -100,13 +118,13 @@ describe ActiveResource::Connection do 
     | 
|
| 
       100 
118 
     | 
    
         
             
                    @e = Dupe.create :expirable_book, :title => 'Impermanence', :state => 'active'
         
     | 
| 
       101 
119 
     | 
    
         
             
                  end
         
     | 
| 
       102 
120 
     | 
    
         | 
| 
       103 
     | 
    
         
            -
                  it "should handle no-content responses" do 
     | 
| 
      
 121 
     | 
    
         
            +
                  it "should handle no-content responses" do
         
     | 
| 
       104 
122 
     | 
    
         
             
                    response = ExpirableBook.find(@e.id).expire_copyrights!
         
     | 
| 
       105 
123 
     | 
    
         
             
                    response.body.should be_blank
         
     | 
| 
       106 
124 
     | 
    
         
             
                    response.code.to_s.should == "204"
         
     | 
| 
       107 
125 
     | 
    
         
             
                  end
         
     | 
| 
       108 
126 
     | 
    
         
             
                end
         
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
       110 
128 
     | 
    
         
             
                it "should parse the xml and turn the result into active resource objects" do
         
     | 
| 
       111 
129 
     | 
    
         
             
                  @book.title.should == "Rooby"
         
     | 
| 
       112 
130 
     | 
    
         
             
                  @ar_book.title = "Rails!"
         
     | 
| 
         @@ -119,13 +137,13 @@ describe ActiveResource::Connection do 
     | 
|
| 
       119 
137 
     | 
    
         
             
                  @book.id.should == 1
         
     | 
| 
       120 
138 
     | 
    
         
             
                  @book.label.should == 'rooby'
         
     | 
| 
       121 
139 
     | 
    
         
             
                end
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
       123 
141 
     | 
    
         
             
                it "should make ActiveResource throw an unprocessable entity exception if our Put mock throws a Dupe::UnprocessableEntity exception" do
         
     | 
| 
       124 
142 
     | 
    
         
             
                  Put %r{/books/(\d+)\.xml} do |id, put_data|
         
     | 
| 
       125 
143 
     | 
    
         
             
                    raise Dupe::UnprocessableEntity.new(:title => " must be present.") unless put_data[:title]
         
     | 
| 
       126 
144 
     | 
    
         
             
                    Dupe.find(:book) {|b| b.id == id.to_i}.merge!(put_data)
         
     | 
| 
       127 
145 
     | 
    
         
             
                  end
         
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
      
 146 
     | 
    
         
            +
             
     | 
| 
       129 
147 
     | 
    
         
             
                  @ar_book.title = nil
         
     | 
| 
       130 
148 
     | 
    
         
             
                  @ar_book.save.should == false
         
     | 
| 
       131 
149 
     | 
    
         
             
                  @ar_book.errors[:base].should_not be_empty
         
     | 
| 
         @@ -147,12 +165,12 @@ describe ActiveResource::Connection do 
     | 
|
| 
       147 
165 
     | 
    
         
             
                  end
         
     | 
| 
       148 
166 
     | 
    
         
             
                  @ar_book = Book.find(1)
         
     | 
| 
       149 
167 
     | 
    
         
             
                end
         
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
       151 
169 
     | 
    
         
             
                it "should pass a request off to the Dupe network if the original request failed" do
         
     | 
| 
       152 
170 
     | 
    
         
             
                  Dupe.network.should_receive(:request).with(:delete, '/books/1.xml').once
         
     | 
| 
       153 
171 
     | 
    
         
             
                  @ar_book.destroy
         
     | 
| 
       154 
172 
     | 
    
         
             
                end
         
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
       156 
174 
     | 
    
         
             
                it "trigger a Dupe.delete to delete the mocked resource from the duped database" do
         
     | 
| 
       157 
175 
     | 
    
         
             
                  Dupe.find(:books).length.should == 1
         
     | 
| 
       158 
176 
     | 
    
         
             
                  @ar_book.destroy
         
     | 
    
        data/spec/lib_specs/dupe_spec.rb
    CHANGED
    
    | 
         @@ -193,7 +193,7 @@ describe Dupe do 
     | 
|
| 
       193 
193 
     | 
    
         
             
                  post_mock.class.should == Dupe::Network::PostMock
         
     | 
| 
       194 
194 
     | 
    
         
             
                  post_mock.url_pattern.should == %r{^/books\.xml$}
         
     | 
| 
       195 
195 
     | 
    
         
             
                  resp, url = post_mock.mocked_response('/books.xml', {:title => "Rooby"})
         
     | 
| 
       196 
     | 
    
         
            -
                  resp.should == Dupe.find(:book).to_xml(:root => 'book')
         
     | 
| 
      
 196 
     | 
    
         
            +
                  Hash.from_xml(resp).should == Hash.from_xml(Dupe.find(:book).to_xml(:root => 'book'))
         
     | 
| 
       197 
197 
     | 
    
         
             
                  url.should == "/books/1.xml"
         
     | 
| 
       198 
198 
     | 
    
         
             
                end
         
     | 
| 
       199 
199 
     | 
    
         | 
    
        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: 21
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 1
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 0
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 1
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 1.0.1
         
     | 
| 
       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: 2012-02-05 00:00:00 Z
         
     | 
| 
       19 
19 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       20 
20 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       21 
21 
     | 
    
         
             
              name: activeresource
         
     | 
| 
         @@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       121 
121 
     | 
    
         
             
            requirements: []
         
     | 
| 
       122 
122 
     | 
    
         | 
| 
       123 
123 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       124 
     | 
    
         
            -
            rubygems_version: 1.8. 
     | 
| 
      
 124 
     | 
    
         
            +
            rubygems_version: 1.8.10
         
     | 
| 
       125 
125 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       126 
126 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       127 
127 
     | 
    
         
             
            summary: Dupe - a testing library for ActiveResource
         
     |