Skip to content

Commit

Permalink
Merge pull request #112 from chargify/reorganizing_remote_specs
Browse files Browse the repository at this point in the history
[internal] Re-organizing remote specs
  • Loading branch information
npverni committed May 14, 2015
2 parents a607be8 + 8b6c7e3 commit 4c8007d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 59 deletions.
52 changes: 43 additions & 9 deletions spec/remote/remote_spec.rb
Expand Up @@ -85,6 +85,14 @@

let(:johnadoes_credit_card) { Chargify::PaymentProfile.create(good_payment_profile_attributes.merge(:customer_id => johnadoe.id)) }

let(:subscription_to_pro) do
Chargify::Subscription.create(
:product_handle => pro_plan.handle,
:customer_reference => johnadoe.reference,
:payment_profile_attributes => good_payment_profile_attributes
)
end

before(:all) do
# Make sure the test site data is set up correctly
clear_site_data; acme_projects; basic_plan; pro_plan; johnadoe; johnadoes_credit_card
Expand All @@ -98,10 +106,10 @@
:uniqueness_token => uniqueness_token,
:product_handle => basic_plan.handle,
:customer_attributes => {
:first_name => "Lil",
:last_name => "Wayne",
:email => "lil.wayne@example.com",
:reference => "lilwayne"
:first_name => "Jane",
:last_name => "Doe",
:email => "jane.doe@example.com",
:reference => "janedoe"
},
:payment_profile_attributes => good_payment_profile_attributes)
}.to_not raise_error
Expand All @@ -111,10 +119,10 @@
:uniqueness_token => uniqueness_token,
:product_handle => basic_plan.handle,
:customer_attributes => {
:first_name => "Lil",
:last_name => "Wayne",
:email => "lil.wayne@example.com",
:reference => "lilwayne"
:first_name => "Jane",
:last_name => "Doe",
:email => "jane.doe@example.com",
:reference => "janedoe"
},
:payment_profile_attributes => good_payment_profile_attributes)
}.to raise_error ActiveResource::ResourceConflict
Expand Down Expand Up @@ -609,7 +617,7 @@

it 'responds with errors when request is invalid' do
response = @subscription.credit(:amount => nil)
expect(response.errors.full_messages.first).to eql "Amount in cents: is not a number."
expect(response.errors.full_messages.first).to eql "Amount: is not a number."
end
end

Expand Down Expand Up @@ -757,6 +765,32 @@
end
end

context "metadata" do
before { subscription_to_pro }
let(:subscription) { Chargify::Subscription.last }

describe 'listing metadata for a subscription' do
it 'returns a list of metadata' do
list = subscription.metadata
expect(list).to eql([])
end
end

describe 'creating a piece of metadata' do
it 'can create a new metadata' do
data = subscription.create_metadata(:name => 'favorite color', :value => 'red')

expect(data).to be_persisted
expect(data.name).to eql('favorite color')
expect(data.value).to eql('red')

list = subscription.metadata
expect(list.size).to eql(1)
expect(list).to include(data)
end
end
end

def clear_site_data
begin
Chargify::Site.clear_data!
Expand Down
4 changes: 2 additions & 2 deletions spec/resources/base_spec.rb
Expand Up @@ -38,13 +38,13 @@
c.subdomain = "first"
end

expect(Chargify::Base.site.to_s).to eql("http://first.chargify.dev")
expect(Chargify::Base.site.to_s).to eql("https://first.chargify.com")

expect do
Chargify.configure do |c|
c.subdomain = "second"
end
end.to change { Chargify::Base.site.to_s }.to("http://second.chargify.dev")
end.to change { Chargify::Base.site.to_s }.to("https://second.chargify.com")

end

Expand Down
41 changes: 0 additions & 41 deletions spec/resources/subscription_metadata_spec.rb
Expand Up @@ -10,45 +10,4 @@
its(:inspect) { should eql("#<Chargify::SubscriptionMetadata resource_id: nil, current_name: nil, name: nil, value: nil>") }
end

describe 'listing metadata for a subscription', :remote => true do
it 'returns a list of metadata' do
subscription, list = nil

VCR.use_cassette 'subscription/find' do
subscription = Chargify::Subscription.last
end

VCR.use_cassette 'subscription_metadata/list' do
list = subscription.metadata
end

expect(list).to eql([])
end
end

describe 'creating a piece of metadata', :remote => true do
it 'can create a new metadata' do
subscription, data, list = nil

VCR.use_cassette 'subscription/find' do
subscription = Chargify::Subscription.last
end

VCR.use_cassette 'subscription_metadata/create' do
# Shorthand for Chargify::SubscriptionMetadata.create(:resource_id => sub.id ...)
data = subscription.create_metadata(:name => 'favorite color', :value => 'red')
end

expect(data).to be_persisted
expect(data.name).to eql('favorite color')
expect(data.value).to eql('red')

VCR.use_cassette 'subscription_metadata/list-after-create' do
list = subscription.metadata
end

expect(list.size).to eql(1)
expect(list).to include(data)
end
end
end
7 changes: 0 additions & 7 deletions spec/spec_helper.rb
Expand Up @@ -13,13 +13,6 @@
ActiveResource::Base.send :include, ActiveResource::FakeResource
FakeWeb.allow_net_connect = false

Chargify.configure do |c|
c.subdomain = ENV['SUBDOMAIN'] || 'acme'
c.api_key = ENV['API_KEY'] || 'acme_test_key'
c.domain = ENV['DOMAIN'] || 'chargify.dev'
c.protocol = ENV['protocol'] || 'http'
end

VCR.configure do |c|
c.allow_http_connections_when_no_cassette = true
c.cassette_library_dir = 'spec/cassettes'
Expand Down

0 comments on commit 4c8007d

Please sign in to comment.