mousetrap 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Mousetrap::Plan do
4
+ # name: Test
5
+ # billingFrequencyQuantity: "1"
6
+ # code: TEST
7
+ # recurringChargeAmount: "42.00"
8
+ # createdDatetime: "2009-08-25T04:24:34+00:00"
9
+ # id: 5fbb9a84-e27f-102c-a92d-40402145ee8b
10
+ # isActive: "1"
11
+ # billingFrequency: monthly
12
+ # description: Test
13
+ # trialDays: "0"
14
+ # setupChargeCode: TEST_SETUP
15
+ # recurringChargeCode: TEST_RECURRING
16
+ # billingFrequencyUnit: months
17
+ # setupChargeAmount: "0.00"
18
+ # billingFrequencyPer: month
19
+
20
+ describe ".all" do
21
+ before do
22
+ Mousetrap::Plan.stub :build_resources_from
23
+ end
24
+
25
+ it "gets all plans" do
26
+ Mousetrap::Plan.should_receive(:get_resources).with('plans').and_return('some hash')
27
+ Mousetrap::Plan.all
28
+ end
29
+
30
+ it "handles no-plans case" do
31
+ Mousetrap::Plan.stub :get_resources => { 'plans' => nil }
32
+ Mousetrap::Plan.all.should == []
33
+ end
34
+
35
+ it "builds resources from the response" do
36
+ Mousetrap::Plan.stub :get_resources => { 'plans' => 'some hash' }
37
+ Mousetrap::Plan.should_receive(:build_resources_from).with({ 'plans' => 'some hash' })
38
+ Mousetrap::Plan.all
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,132 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ module Mousetrap
4
+ class Widget < Resource
5
+ attr_accessor :id
6
+ attr_accessor :code
7
+
8
+
9
+ protected
10
+
11
+ def self.attributes_from_api(attributes)
12
+ {
13
+ :id => attributes['id'],
14
+ :code => attributes['code'],
15
+ }
16
+ end
17
+
18
+ def self.plural_resource_name
19
+ 'widgets'
20
+ end
21
+
22
+ def self.singular_resource_name
23
+ 'widget'
24
+ end
25
+ end
26
+ end
27
+
28
+ describe Mousetrap::Resource do
29
+ before do
30
+ Mousetrap.product_code = 'my_product_code'
31
+ end
32
+
33
+ subject { Mousetrap::Resource }
34
+
35
+ describe "class" do
36
+ it "sets the base URI" do
37
+ subject.default_options[:base_uri].should == 'https://cheddargetter.com'
38
+ end
39
+
40
+ it "set the header to our client name" do
41
+ subject.headers['User-Agent'].should == 'Mousetrap Ruby Client'
42
+ end
43
+ end
44
+
45
+ describe ".[]" do
46
+ before do
47
+ customer_hash = Factory.attributes_for :existing_customer
48
+ customer_hash = HashWithIndifferentAccess.new customer_hash
49
+ @code = customer_hash[:code]
50
+ @server_response_hash = { 'widgets' => { 'widget' => customer_hash } }
51
+ Mousetrap::Widget.stub(:get_resource => @server_response_hash)
52
+ end
53
+
54
+ it "gets a resource with widget code" do
55
+ Mousetrap::Widget.should_receive(:get_resource).with('widgets', @code).and_return(@server_response_hash)
56
+ Mousetrap::Widget[@code]
57
+ end
58
+
59
+ context "returned widget instance" do
60
+ subject { Mousetrap::Widget[@code] }
61
+ it { should be_instance_of(Mousetrap::Widget) }
62
+ it { should_not be_new_record }
63
+ it { subject.code.should == @code }
64
+ end
65
+ end
66
+
67
+ describe ".destroy_all" do
68
+ it "destroys each resource" do
69
+ all_widgets = [stub, stub, stub]
70
+ Mousetrap::Widget.stub :all => all_widgets
71
+ all_widgets.each { |w| w.should_receive :destroy }
72
+ Mousetrap::Widget.destroy_all
73
+ end
74
+ end
75
+
76
+ describe '#destroy' do
77
+ context "for existing records" do
78
+ it 'destroys' do
79
+ widget = Mousetrap::Widget.new
80
+ widget.stub :new_record? => false
81
+ widget.should_receive(:member_action).with('delete')
82
+ widget.destroy
83
+ end
84
+ end
85
+
86
+ context "for new records" do
87
+ it "does nothing" do
88
+ widget = Mousetrap::Widget.new
89
+ widget.stub :new_record? => true
90
+ Mousetrap::Customer.should_not_receive(:member_action)
91
+ widget.destroy
92
+ end
93
+ end
94
+ end
95
+
96
+ describe ".delete_resource" do
97
+ it "gets /xml/<resource>/delete/productCode/<my_product_code>/code/<resource_code>" do
98
+ subject.should_receive(:post).with('/xml/widgets/delete/productCode/my_product_code/code/some_resource_code')
99
+ subject.delete_resource 'widgets', 'some_resource_code'
100
+ end
101
+ end
102
+
103
+ describe ".get_resource" do
104
+ it "gets /xml/<resource>/get/productCode/<my_product_code>/code/<resource_code>" do
105
+ subject.should_receive(:get).with('/xml/widgets/get/productCode/my_product_code/code/some%2Bresource%2Bcode')
106
+ subject.get_resource 'widgets', 'some+resource+code'
107
+ end
108
+ end
109
+
110
+ describe ".get_resources" do
111
+ it "gets /xml/<resource>/get/productCode/<my_product_code>" do
112
+ subject.should_receive(:get).with('/xml/widgets/get/productCode/my_product_code')
113
+ subject.get_resources 'widgets'
114
+ end
115
+ end
116
+
117
+ describe ".post_resource" do
118
+ it "posts to /xml/<resource>/<action>/productCode/<product_code>" do
119
+ subject.should_receive(:post).with('/xml/widgets/some_action/productCode/my_product_code', :body => 'some_hash')
120
+ subject.post_resource 'widgets', 'some_action', 'some_hash'
121
+ end
122
+ end
123
+
124
+ describe ".put_resource" do
125
+ it "puts to /xml/<resource>/<action>/productCode/<product_code>/code/<resource_code>" do
126
+ subject.should_receive(:post).with(
127
+ '/xml/widgets/some_action/productCode/my_product_code/code/some_widget_code',
128
+ :body => 'some_hash')
129
+ subject.put_resource 'widgets', 'some_action', 'some_widget_code', 'some_hash'
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ FULL_CUSTOMER ={"company"=>nil, "lastName"=>"LasterName1255024322", "code"=>"1255024322", "gatewayToken"=>nil, "createdDatetime"=>"2009-10-08T17:55:30+00:00", "modifiedDatetime"=>"2009-10-08T17:55:30+00:00", "subscriptions"=>{"subscription"=>[{"ccExpirationDate"=>"2010-01-31T00:00:00+00:00", "plans"=>{"plan"=>{"name"=>"Plus", "billingFrequencyQuantity"=>"1", "code"=>"PLUS", "recurringChargeAmount"=>"49.00", "createdDatetime"=>"2009-10-06T14:54:24+00:00", "id"=>"51a912d0-03d8-102d-a92d-40402145ee8b", "isActive"=>"1", "billingFrequency"=>"monthly", "description"=>nil, "trialDays"=>"0", "setupChargeCode"=>"PLUS_SETUP", "recurringChargeCode"=>"PLUS_RECURRING", "billingFrequencyUnit"=>"months", "setupChargeAmount"=>"49.00", "billingFrequencyPer"=>"month"}}, "gatewayToken"=>nil, "createdDatetime"=>"2009-10-08T17:55:31+00:00", "ccType"=>"visa", "id"=>"f426d5ae-0583-102d-a92d-40402145ee8b", "ccLastFour"=>"2222", "canceledDatetime"=>nil, "invoices"=>{"invoice"=>{"number"=>"12", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "type"=>"subscription", "billingDatetime"=>"2009-11-08T17:55:30+00:00", "id"=>"f3142928-0583-102d-a92d-40402145ee8b"}}}, {"ccExpirationDate"=>"2010-01-31T00:00:00+00:00", "plans"=>{"plan"=>{"name"=>"Basic", "billingFrequencyQuantity"=>"1", "code"=>"BASIC", "recurringChargeAmount"=>"24.00", "createdDatetime"=>"2009-10-06T14:53:49+00:00", "id"=>"3cd2e840-03d8-102d-a92d-40402145ee8b", "isActive"=>"1", "billingFrequency"=>"monthly", "description"=>nil, "trialDays"=>"0", "setupChargeCode"=>"BASIC_SETUP", "recurringChargeCode"=>"BASIC_RECURRING", "billingFrequencyUnit"=>"months", "setupChargeAmount"=>"24.00", "billingFrequencyPer"=>"month"}}, "gatewayToken"=>nil, "createdDatetime"=>"2009-10-08T17:55:30+00:00", "ccType"=>"visa", "id"=>"f30e0e94-0583-102d-a92d-40402145ee8b", "ccLastFour"=>"2222", "canceledDatetime"=>nil, "invoices"=>{"invoice"=>{"number"=>"11", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "transactions"=>{"transaction"=>{"response"=>"approved", "code"=>"", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "memo"=>"This is a simulated transaction", "id"=>"f327b178-0583-102d-a92d-40402145ee8b", "parentId"=>nil, "amount"=>"24.00", "transactedDatetime"=>"2009-10-08T17:55:30+00:00", "gatewayAccount"=>{"id"=>""}, "charges"=>{"charge"=>{"code"=>"BASIC_SETUP", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "type"=>"setup", "quantity"=>"1", "id"=>"f325406e-0583-102d-a92d-40402145ee8b", "description"=>nil, "eachAmount"=>"24.00"}}}}, "type"=>"setup", "billingDatetime"=>"2009-10-08T17:55:30+00:00", "id"=>"f3125468-0583-102d-a92d-40402145ee8b"}}}]}, "id"=>"f30cd614-0583-102d-a92d-40402145ee8b", "firstName"=>"FirsterName1", "email"=>"example1@example.com"}
4
+ MULTIPLE_SUBSCRIPTIONS =[{"ccExpirationDate"=>"2010-01-31T00:00:00+00:00", "plans"=>{"plan"=>{"name"=>"Plus", "billingFrequencyQuantity"=>"1", "code"=>"PLUS", "recurringChargeAmount"=>"49.00", "createdDatetime"=>"2009-10-06T14:54:24+00:00", "id"=>"51a912d0-03d8-102d-a92d-40402145ee8b", "isActive"=>"1", "billingFrequency"=>"monthly", "description"=>nil, "trialDays"=>"0", "setupChargeCode"=>"PLUS_SETUP", "recurringChargeCode"=>"PLUS_RECURRING", "billingFrequencyUnit"=>"months", "setupChargeAmount"=>"49.00", "billingFrequencyPer"=>"month"}}, "gatewayToken"=>nil, "createdDatetime"=>"2009-10-08T17:55:31+00:00", "ccType"=>"visa", "id"=>"f426d5ae-0583-102d-a92d-40402145ee8b", "ccLastFour"=>"2222", "canceledDatetime"=>nil, "invoices"=>{"invoice"=>{"number"=>"12", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "type"=>"subscription", "billingDatetime"=>"2009-11-08T17:55:30+00:00", "id"=>"f3142928-0583-102d-a92d-40402145ee8b"}}}, {"ccExpirationDate"=>"2010-01-31T00:00:00+00:00", "plans"=>{"plan"=>{"name"=>"Basic", "billingFrequencyQuantity"=>"1", "code"=>"BASIC", "recurringChargeAmount"=>"24.00", "createdDatetime"=>"2009-10-06T14:53:49+00:00", "id"=>"3cd2e840-03d8-102d-a92d-40402145ee8b", "isActive"=>"1", "billingFrequency"=>"monthly", "description"=>nil, "trialDays"=>"0", "setupChargeCode"=>"BASIC_SETUP", "recurringChargeCode"=>"BASIC_RECURRING", "billingFrequencyUnit"=>"months", "setupChargeAmount"=>"24.00", "billingFrequencyPer"=>"month"}}, "gatewayToken"=>nil, "createdDatetime"=>"2009-10-08T17:55:30+00:00", "ccType"=>"visa", "id"=>"f30e0e94-0583-102d-a92d-40402145ee8b", "ccLastFour"=>"2222", "canceledDatetime"=>nil, "invoices"=>{"invoice"=>{"number"=>"11", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "transactions"=>{"transaction"=>{"response"=>"approved", "code"=>"", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "memo"=>"This is a simulated transaction", "id"=>"f327b178-0583-102d-a92d-40402145ee8b", "parentId"=>nil, "amount"=>"24.00", "transactedDatetime"=>"2009-10-08T17:55:30+00:00", "gatewayAccount"=>{"id"=>""}, "charges"=>{"charge"=>{"code"=>"BASIC_SETUP", "createdDatetime"=>"2009-10-08T17:55:30+00:00", "type"=>"setup", "quantity"=>"1", "id"=>"f325406e-0583-102d-a92d-40402145ee8b", "description"=>nil, "eachAmount"=>"24.00"}}}}, "type"=>"setup", "billingDatetime"=>"2009-10-08T17:55:30+00:00", "id"=>"f3125468-0583-102d-a92d-40402145ee8b"}}}]
5
+
6
+
7
+ describe Mousetrap::Subscription do
8
+ # subscription:
9
+ # ccExpirationDate: "2010-01-31T00:00:00+00:00"
10
+ # gatewayToken:
11
+ # createdDatetime: "2009-08-27T15:55:51+00:00"
12
+ # ccType: visa
13
+ # id: 46ad3f1c-e472-102c-a92d-40402145ee8b
14
+ # ccLastFour: "1111"
15
+ # canceledDatetime:
16
+
17
+
18
+ describe "plan" do
19
+ it 'has the correct planCode populated' do
20
+ Mousetrap::Subscription.new_from_api(MULTIPLE_SUBSCRIPTIONS.first).plan.code.should == "PLUS"
21
+ end
22
+
23
+ it 'exists' do
24
+ Mousetrap::Subscription.new_from_api(MULTIPLE_SUBSCRIPTIONS.first).plan.should_not be_nil
25
+ end
26
+ end
27
+ describe '#destroy' do
28
+ it "raises a NotImplementedError" do
29
+ expect do
30
+ Mousetrap::Subscription.new.destroy
31
+ end.to raise_error(NotImplementedError)
32
+ end
33
+ end
34
+
35
+ describe '::attributes_for_api' do
36
+ it 'coerces the month to 2 digits' do
37
+ Mousetrap::Subscription.attributes_for_api(
38
+ :credit_card_expiration_month => 2
39
+ )[:ccExpMonth].should == '02'
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Mousetrap do
4
+ subject { Mousetrap }
5
+
6
+ it "stores product code" do
7
+ subject.product_code = 'my_product_code'
8
+ subject.product_code.should == 'my_product_code'
9
+ end
10
+
11
+ describe "#authenticate" do
12
+ it "sets basic auth based on the supplied user and password" do
13
+ Mousetrap::Resource.should_receive(:basic_auth).with('lark@example.com', 'abc123')
14
+ subject.authenticate 'lark@example.com', 'abc123'
15
+ end
16
+ end
17
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'mousetrap'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'factory_girl'
7
+ require 'active_support'
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ module Mousetrap
14
+ class Resource
15
+ def self.get(*args)
16
+ raise 'You must stub this, or should_receive at a higher level.'
17
+ end
18
+
19
+ def self.post(*args)
20
+ raise 'You must stub this, or should_receive at a higher level.'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ def random_email_address
2
+ "#{random_string}@example.com"
3
+ end
4
+
5
+ def random_string
6
+ random_alpha_string_of_length(10)
7
+ end
8
+
9
+ def random_alpha_string_of_length(length)
10
+ letters = *'a'..'z'
11
+ random_string_for_uniqueness = ''
12
+ length.times { random_string_for_uniqueness += letters[rand(letters.size - 1)]}
13
+ random_string_for_uniqueness
14
+ end
15
+
16
+ def random_number_string_of_length(length)
17
+ numbers = *'0'..'9'
18
+ random_string_for_uniqueness = ''
19
+ length.times { random_string_for_uniqueness += numbers[rand(numbers.size - 1)]}
20
+ random_string_for_uniqueness
21
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mousetrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ platform: ruby
6
+ authors:
7
+ - Jon Larkowski
8
+ - Sandro Turriate
9
+ - Wolfram Arnold
10
+ - Corey Grusden
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+
15
+ date: 2009-10-12 00:00:00 -04:00
16
+ default_executable:
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: httparty
20
+ type: :runtime
21
+ version_requirement:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.2
27
+ version:
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ type: :development
31
+ version_requirement:
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.3.3
37
+ version:
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ type: :development
41
+ version_requirement:
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.2.8
47
+ version:
48
+ - !ruby/object:Gem::Dependency
49
+ name: thoughtbot-factory_girl
50
+ type: :development
51
+ version_requirement:
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 1.2.2
57
+ version:
58
+ description: CheddarGetter API Client in Ruby
59
+ email: jonlarkowski@gmail.com
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ extra_rdoc_files:
65
+ - README.textile
66
+ files:
67
+ - .document
68
+ - .gitignore
69
+ - MIT-LICENSE
70
+ - README.textile
71
+ - Rakefile
72
+ - VERSION
73
+ - lib/mousetrap.rb
74
+ - lib/mousetrap/customer.rb
75
+ - lib/mousetrap/plan.rb
76
+ - lib/mousetrap/resource.rb
77
+ - lib/mousetrap/subscription.rb
78
+ - mousetrap.gemspec
79
+ - spec/factories.rb
80
+ - spec/integration/settings.example.yml
81
+ - spec/integration/smoke_test.rb
82
+ - spec/integration/spike.rb
83
+ - spec/mousetrap/customer_spec.rb
84
+ - spec/mousetrap/plan_spec.rb
85
+ - spec/mousetrap/resource_spec.rb
86
+ - spec/mousetrap/subscription_spec.rb
87
+ - spec/mousetrap_spec.rb
88
+ - spec/spec.opts
89
+ - spec/spec_helper.rb
90
+ - spec/support/random_data.rb
91
+ has_rdoc: true
92
+ homepage: http://github.com/hashrocket/mousetrap
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --charset=UTF-8
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ version:
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: "0"
111
+ version:
112
+ requirements: []
113
+
114
+ rubyforge_project:
115
+ rubygems_version: 1.3.5
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: CheddarGetter API Client in Ruby
119
+ test_files:
120
+ - spec/factories.rb
121
+ - spec/integration/smoke_test.rb
122
+ - spec/integration/spike.rb
123
+ - spec/mousetrap/customer_spec.rb
124
+ - spec/mousetrap/plan_spec.rb
125
+ - spec/mousetrap/resource_spec.rb
126
+ - spec/mousetrap/subscription_spec.rb
127
+ - spec/mousetrap_spec.rb
128
+ - spec/spec_helper.rb
129
+ - spec/support/random_data.rb