Skip to content

Commit

Permalink
Merge remote-tracking branch 'aceofsales/update-test-suite' into 0-6-…
Browse files Browse the repository at this point in the history
…stable

Conflicts:
	.gitignore
  • Loading branch information
moklett committed Feb 16, 2013
2 parents 93ad072 + e38d141 commit 7d041e2
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 119 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,5 @@ spec/remote/remote.yml
pkg
.rvmrc
.ruby-version
.bundle/
bin/
35 changes: 18 additions & 17 deletions Gemfile.lock
Expand Up @@ -19,8 +19,8 @@ GEM
builder (3.0.4)
coderay (1.0.8)
diff-lcs (1.1.3)
factory_girl (2.1.2)
activesupport
factory_girl (4.2.0)
activesupport (>= 3.0.0)
faker (1.1.2)
i18n (~> 0.5)
fakeweb (1.3.0)
Expand All @@ -31,8 +31,9 @@ GEM
pry (>= 0.9.10)
terminal-table (>= 1.4.3)
thor (>= 0.14.6)
guard-rspec (0.5.11)
guard (>= 0.8.4)
guard-rspec (2.4.0)
guard (>= 1.1)
rspec (~> 2.11)
i18n (0.6.1)
listen (0.7.2)
lumberjack (1.0.2)
Expand All @@ -42,16 +43,16 @@ GEM
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
rake (0.9.6)
rake (10.0.3)
rb-fsevent (0.9.3)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.7.0)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
slop (3.4.3)
terminal-table (1.4.5)
thor (0.17.0)
Expand All @@ -61,11 +62,11 @@ PLATFORMS

DEPENDENCIES
chargify_api_ares!
factory_girl (~> 2.1.0)
factory_girl (~> 4.2.0)
faker (~> 1.1.2)
fakeweb (~> 1.3.0)
growl (~> 1.0.3)
guard-rspec (~> 0.5.0)
rake (~> 0.9.2)
guard-rspec (~> 2.4.0)
rake (~> 10.0.3)
rb-fsevent (~> 0.9.2)
rspec (~> 2.7.0)
rspec (~> 2.12.0)
3 changes: 1 addition & 2 deletions Rakefile
@@ -1,5 +1,4 @@
require 'bundler'
Bundler::GemHelper.install_tasks
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |t|
Expand Down
8 changes: 4 additions & 4 deletions chargify_api_ares.gemspec
Expand Up @@ -20,12 +20,12 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('activeresource', '>= 2.3.5')

# Development Dependencies
s.add_development_dependency('rake', '~> 0.9.2')
s.add_development_dependency('rspec', '~> 2.7.0')
s.add_development_dependency('factory_girl', '~> 2.1.0')
s.add_development_dependency('rake', '~> 10.0.3')
s.add_development_dependency('rspec', '~> 2.12.0')
s.add_development_dependency('factory_girl', '~> 4.2.0')
s.add_development_dependency('fakeweb', '~> 1.3.0')
s.add_development_dependency('faker', '~> 1.1.2')
s.add_development_dependency('guard-rspec', '~> 0.5.0')
s.add_development_dependency('guard-rspec', '~> 2.4.0')
s.add_development_dependency('growl', '~> 1.0.3')
s.add_development_dependency('rb-fsevent', '~> 0.9.2')
end
4 changes: 2 additions & 2 deletions spec/factories.rb
Expand Up @@ -22,14 +22,14 @@
factory :customer, :class => Chargify::Customer do |f|
f.first_name { Faker::Name.first_name }
f.last_name { Faker::Name.last_name }
f.email { FactoryGirl.generate(:email) }
f.email { generate(:email) }
f.organization { Faker::Company.name }
f.created_at { 2.days.ago }
f.updated_at { 1.hour.ago }
end

factory :product, :class => Chargify::Product do |f|
f.name { FactoryGirl.generate(:product_name) }
f.name { generate(:product_name) }
end

factory :product_family, :class => Chargify::ProductFamily do |f|
Expand Down
11 changes: 2 additions & 9 deletions spec/remote/spec_helper.rb → spec/remote/remote_helper.rb
@@ -1,20 +1,13 @@
require 'rubygems'
require 'rspec'
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
require 'spec_helper'

require 'chargify_api_ares'
FakeWeb.allow_net_connect = true

unless File.exists?(File.join(File.dirname(__FILE__), 'remote.yml'))
STDERR.puts "\nERROR: Make sure a remote.yml file exists at ./spec/remote/remote.yml\n\n"
abort
end

RSpec.configure do |config|
config.filter_run :focused => true
config.run_all_when_everything_filtered = true
config.alias_example_to :fit, :focused => true
config.color_enabled = true
config.before(:all) do
Chargify.configure do |c|
c.api_key = remote_configuration['api_key']
Expand Down
2 changes: 1 addition & 1 deletion spec/remote/remote_spec.rb
@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'remote/remote_helper'

describe "Remote" do

Expand Down
10 changes: 5 additions & 5 deletions spec/resources/coupon_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'

describe Chargify::Coupon do
describe Chargify::Coupon, :fake_resource do
context '.find_by_product_family_id_and_code' do
let(:existing_coupon) { Factory.build(:coupon, :code => '20OFF') }
let(:existing_coupon) { build(:coupon, :code => '20OFF') }

before(:each) do
FakeWeb.register_uri(:get, "#{test_domain}/coupons/lookup.xml?code=#{existing_coupon.code}&product_family_id=10", :body => existing_coupon.attributes.to_xml)
Expand All @@ -24,8 +24,8 @@
end

context '.find_all_by_product_family_id' do
let(:coupon_1) { Factory.build(:coupon, :product_family_id => 5) }
let(:coupon_2) { Factory.build(:coupon, :product_family_id => 5) }
let(:coupon_1) { build(:coupon, :product_family_id => 5) }
let(:coupon_2) { build(:coupon, :product_family_id => 5) }

before do
FakeWeb.register_uri(:get, "#{test_domain}/coupons.xml?product_family_id=5", :body => [coupon_1.attributes, coupon_2.attributes].to_xml)
Expand All @@ -39,7 +39,7 @@
end

context '.validate' do
let(:coupon_1) { Factory.build(:coupon, :product_family_id => 6) }
let(:coupon_1) { build(:coupon, :product_family_id => 6) }

before do
FakeWeb.register_uri(:get, "#{test_domain}/coupons/validate.xml?product_family_id=6&coupon_code=foobar123", :body => coupon_1.attributes.to_xml)
Expand Down
2 changes: 1 addition & 1 deletion spec/resources/customer_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Chargify::Customer do
describe Chargify::Customer, :fake_resource do
context '.find_by_reference' do
let(:existing_customer) { Chargify::Customer.create(:id => 5, :reference => 'sigma') }

Expand Down
9 changes: 3 additions & 6 deletions spec/resources/product_family_component_spec.rb
Expand Up @@ -11,8 +11,7 @@
response.stub(:tap)
end

# Not compatible with FakeResource. Will be re-introduced in 0.6.0
xit 'should post to the correct url' do
it 'should post to the correct url' do
connection.should_receive(:post) do |path, body, headers|
path.should == '/product_families/123/quantity_based_components.xml'

Expand All @@ -22,8 +21,7 @@
component.create(:product_family_id => 123, :kind => 'quantity_based_component', :name => 'Foo Component')
end

# Not compatible with FakeResource. Will be re-introduced in 0.6.0
xit 'should not include the kind attribute in the post' do
it 'should not include the kind attribute in the post' do
connection.should_receive(:post) do |path, body, headers|
body.should_not match(/kind/)

Expand All @@ -33,8 +31,7 @@
component.create(:product_family_id => 123, :kind => 'quantity_based_component', :name => 'Foo Component')
end

# Not compatible with FakeResource. Will be re-introduced in 0.6.0
xit 'should have the component kind as the root' do
it 'should have the component kind as the root' do
connection.should_receive(:post) do |path, body, headers|
#The second line in the xml should be the root. This saves us from using nokogiri for this one example.
body.split($/)[1].should match(/quantity_based_component/)
Expand Down
2 changes: 1 addition & 1 deletion spec/resources/product_family_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Chargify::ProductFamily do
describe Chargify::ProductFamily, :fake_resource do
context ".find_by_handle" do
let(:product_family) { Chargify::ProductFamily.create(:id => 1, :handle => 'farming') }

Expand Down
2 changes: 1 addition & 1 deletion spec/resources/product_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Chargify::Product do
describe Chargify::Product, :fake_resource do

context '.find_by_handle' do
let(:existing_product) { Chargify::Product.create(:id => 2, :handle => 'green-money') }
Expand Down
2 changes: 1 addition & 1 deletion spec/resources/subscription_component_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Chargify::Subscription::Component do
describe Chargify::Subscription::Component, :fake_resource do
before(:each) do
@subscription = Chargify::Subscription.new(:id => 1)
@sc1 = Chargify::Subscription::Component.new(
Expand Down
20 changes: 10 additions & 10 deletions spec/resources/subscription_spec.rb
@@ -1,10 +1,10 @@
require 'spec_helper'

describe Chargify::Subscription do
describe Chargify::Subscription, :fake_resource do

context 'strips nested association attributes before saving' do
before do
@subscription = FactoryGirl.build(:subscription_with_extra_attrs)
@subscription = build(:subscription_with_extra_attrs)
end

it 'strips customer' do
Expand All @@ -26,15 +26,15 @@
end

it "doesn't strip other attrs" do
subscription = FactoryGirl.build(:subscription)
subscription = build(:subscription)

lambda { subscription.save! }.should_not change(subscription, :attributes)
end
end

it 'creates a one-time charge' do
id = FactoryGirl.generate(:subscription_id)
subscription = Factory(:subscription, :id => id)
id = generate(:subscription_id)
subscription = build(:subscription, :id => id)
subscription.stub!(:persisted?).and_return(true)
expected_response = {:charge => {:amount_in_cents => 1000, :memo => "one-time charge", :success => true}}.to_xml
FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/charges.xml", :status => 201, :body => expected_response)
Expand All @@ -46,8 +46,8 @@
end

it 'finds by customer reference' do
customer = Factory(:customer, :reference => 'roger', :id => 10)
subscription = Factory(:subscription, :id => 11, :customer_id => customer.id, :product => Factory(:product))
customer = build(:customer, :reference => 'roger', :id => 10)
subscription = build(:subscription, :id => 11, :customer_id => customer.id, :product => build(:product))

expected_response = [subscription.attributes].to_xml(:root => 'subscriptions')
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions.xml?customer_id=#{customer.id}", :status => 200, :body => expected_response)
Expand All @@ -57,7 +57,7 @@
end

it 'cancels the subscription' do
@subscription = Factory(:subscription, :id => 1)
@subscription = build(:subscription, :id => 1)
find_subscription = lambda { Chargify::Subscription.find(1) }

FakeWeb.register_uri(:get, "#{test_domain}/subscriptions/1.xml", :body => @subscription.attributes.to_xml)
Expand All @@ -68,8 +68,8 @@
end

it 'migrates the subscription' do
id = FactoryGirl.generate(:subscription_id)
subscription = Factory(:subscription, :id => id)
id = generate(:subscription_id)
subscription = build(:subscription, :id => id)
subscription.stub!(:persisted?).and_return(true)
expected_response = [subscription.attributes].to_xml(:root => 'subscription')
FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/migrations.xml?migration%5Bproduct_handle%5D=upgraded-plan", :status => 201, :body => expected_response)
Expand Down
10 changes: 5 additions & 5 deletions spec/resources/usage_spec.rb
@@ -1,10 +1,10 @@
require 'spec_helper'

describe Chargify::Usage do
describe Chargify::Usage, :fake_resource do
context "create" do
before do
@subscription = Factory(:subscription)
@component = Factory(:component)
@subscription = build(:subscription)
@component = build(:component)
@now = DateTime.now.to_s
end

Expand All @@ -24,8 +24,8 @@

context "find" do
before do
@subscription = Factory(:subscription)
@component = Factory(:component)
@subscription = build(:subscription)
@component = build(:component)
@now = DateTime.now.to_s
end

Expand Down
23 changes: 14 additions & 9 deletions spec/spec_helper.rb
@@ -1,13 +1,11 @@
$:.unshift File.expand_path('../lib', File.dirname(__FILE__))

require 'chargify_api_ares'
require 'rspec'
require 'fakeweb'
require 'bundler'
Bundler.require(:default, :development)

require 'support/fake_resource'
require 'factory_girl'
require 'faker'
require 'factories'

FactoryGirl.find_definitions
ActiveResource::Base.send :include, ActiveResource::FakeResource
FakeWeb.allow_net_connect = false

Expand All @@ -19,11 +17,18 @@
RSpec.configure do |config|
config.filter_run :focused => true
config.run_all_when_everything_filtered = true
config.treat_symbols_as_metadata_keys_with_true_values = true
config.alias_example_to :fit, :focused => true
config.color_enabled = true

config.after(:each) do
ActiveResource::FakeResource.clean

config.include FactoryGirl::Syntax::Methods

config.before(:each, :fake_resource) do
ActiveResource::FakeResource.enable
end

config.after(:each, :fake_resource) do
ActiveResource::FakeResource.disable
end
end

Expand Down

0 comments on commit 7d041e2

Please sign in to comment.