Skip to content
Browse files

Add IpAddress#edit method

  • Loading branch information...
1 parent ff311b5 commit c909b7f08bedfdf12d039d6b41bbd280d473109c @itspriddle itspriddle committed May 16, 2011
Showing with 91 additions and 0 deletions.
  1. +11 −0 lib/squall/ip_address.rb
  2. +40 −0 spec/squall/ip_address_spec.rb
  3. +40 −0 spec/vcr_cassettes/ipaddress/edit.yml
View
11 lib/squall/ip_address.rb
@@ -9,5 +9,16 @@ def list(network_id)
response = request(:get, "/settings/networks/#{network_id}/ip_addresses.json")
response.collect { |ip| ip['ip_address'] }
end
+
+ # Updates an existing IpAddress
+ #
+ # ==== Options
+ # * +network_id+ - required
+ # * +id+ - required
+ # * +options+ - Params for updating the IpAddress
+ def edit(network_id, id, options = {})
+ params.required(:address, :netmask, :broadcast, :network_address, :gateway).validate!(options)
+ response = request(:put, "/settings/networks/#{network_id}/ip_addresses/#{id}.json", default_params(options))
+ end
end
end
View
40 spec/squall/ip_address_spec.rb
@@ -29,4 +29,44 @@
first['address'].should == '127.2.2.2'
end
end
+
+ describe "#edit" do
+ use_vcr_cassette 'ipaddress/edit'
+
+ ip_params = {
+ :address => '109.123.91.67',
+ :netmask => '255.255.255.193',
+ :broadcast => '109.123.91.128',
+ :network_address => '109.123.91.65',
+ :gateway => '109.123.91.66'
+ }
+
+ it "raises ArgumentError without required arguments" do
+ expect { @ip.edit }.to raise_error(ArgumentError)
+ end
+
+ it "raises ArgumentError without id argument" do
+ expect { @ip.edit(1) }.to raise_error(ArgumentError)
+ end
+
+ it "raises ArgumentError without required options" do
+ expect { @ip.edit(1, 1, {}) }.to raise_error(ArgumentError)
+ end
+
+ it "edits the IpAddress" do
+ ip = @ip.edit(1, 1, ip_params)
+ @ip.success.should be_true
+
+ # OnApp isn't returning the updated IP info right now, we can uncomment
+ # this when it's fixed
+
+ # ip.keys.should include(*%w[address netmask broadcast network_address gateway])
+ #
+ # ip['address'].should == '109.123.91.67'
+ # ip['netmask'].should == '255.255.255.193'
+ # ip['broadcast'].should == '109.123.91.128'
+ # ip['network_address'].should == '109.123.91.65'
+ # ip['gateway'].should == '109.123.91.66'
+ end
+ end
end
View
40 spec/vcr_cassettes/ipaddress/edit.yml
@@ -0,0 +1,40 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :put
+ uri: http://user:pass@www.example.com:80/settings/networks/1/ip_addresses/1.json?ip_address[netmask]=255.255.255.193&ip_address[network_address]=109.123.91.65&ip_address[gateway]=109.123.91.66&ip_address[address]=109.123.91.67&ip_address[broadcast]=109.123.91.128
+ body:
+ headers:
+ content-type:
+ - application/json
+ authorization:
+ - Basic WHAT
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ etag:
+ - "\"99914b932bd37a50b983c5e7c90ae93b\""
+ x-powered-by:
+ - Phusion Passenger (mod_rails/mod_rack) 3.0.1
+ content-type:
+ - application/json; charset=utf-8
+ x-runtime:
+ - "12.584432"
+ server:
+ - Apache/2.2.3 (CentOS)
+ date:
+ - Mon, 16 May 2011 19:30:27 GMT
+ set-cookie:
+ - _onapp_session=WHAT; path=/; HttpOnly
+ status:
+ - "200"
+ cache-control:
+ - max-age=0, private, must-revalidate
+ transfer-encoding:
+ - chunked
+ body: "{}"
+ http_version: "1.1"

0 comments on commit c909b7f

Please sign in to comment.
Something went wrong with that request. Please try again.