test/spec/fees_spec.rb in openpay-1.0.3 vs test/spec/fees_spec.rb in openpay-1.0.4

- old
+ new

@@ -16,16 +16,19 @@ @fees=@openpay.create(:fees) end - after(:all) do - @bank_accounts.delete_all @customers.delete_all end + it 'has all required methods' do + %w(all each create get list delete).each do |meth| + expect(@customers).to respond_to(meth) + end + end describe '.create' do #In order to create a fee a charge should exists it 'creates a fee ' do @@ -52,11 +55,10 @@ @cards.delete(card['id'], customer['id']) @customers.delete(customer['id']) end - it 'creates a fee using a json message' do #create new customer customer_hash= FactoryGirl.build(:customer) customer=@customers.create(customer_hash) @@ -75,16 +77,23 @@ end end + describe '.each' do + it 'iterates over all elements' do + @fees.each do |fee| + expect(fee['description']).to match /\s+/ + end + end + end - describe '.all' do + describe '.list' do - it 'get all fees' do + it 'list fees with a given filter' do #create new customer customer_hash= FactoryGirl.build(:customer) customer=@customers.create(customer_hash) @@ -98,19 +107,54 @@ #create customer fee fee_hash = FactoryGirl.build(:fee, customer_id: customer['id']) @fees.create(fee_hash) + #create customer fee + fee_hash = FactoryGirl.build(:fee, customer_id: customer['id']) + @fees.create(fee_hash) + + #performs check - expect(@fees.all.first['amount']).to be_a Float + search_params = OpenpayUtils::SearchParams.new + search_params.limit = 1 + expect(@fees.list(search_params).size).to eq 1 + #cleanup @cards.delete(card['id'], customer['id']) @customers.delete(customer['id']) end + end -end + describe '.all' do + it 'get all fees' do + #create new customer + customer_hash= FactoryGirl.build(:customer) + customer=@customers.create(customer_hash) + #create customer card + card_hash=FactoryGirl.build(:valid_card) + card=@cards.create(card_hash, customer['id']) + + #create charge + charge_hash=FactoryGirl.build(:card_charge, source_id: card['id'], order_id: card['id'], amount: 4000) + @charges.create(charge_hash, customer['id']) + + #create customer fee + fee_hash = FactoryGirl.build(:fee, customer_id: customer['id']) + @fees.create(fee_hash) + + #performs check + expect(@fees.all.first['amount']).to be_a Float + + #cleanup + @cards.delete(card['id'], customer['id']) + @customers.delete(customer['id']) + + end + end +end