summaryrefslogtreecommitdiff
path: root/billing/test/functional/customers_controller_test.rb
blob: 45a14ed11b81dc37d8841127bd7b66e34d27903c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'test_helper'

class CustomersControllerTest < ActionController::TestCase

  setup do
    @user = FactoryGirl.create :user
    @other_user = FactoryGirl.create :user
    FakeBraintree.clear!
    FakeBraintree.verify_all_cards!
    testid = 'testid'
    FakeBraintree::Customer.new({:credit_cards => [{:number=>"5105105105105100", :expiration_date=>"05/2013"}]}, {:id => testid, :merchant_id => Braintree::Configuration.merchant_id})
    # any reason to call the create instance method on the FakeBraintree::Customer ?
    @customer = Customer.new(:user_id => @other_user.id)
    @customer.braintree_customer_id = testid
    @customer.save

  end

  teardown do
    @user.destroy
    @other_user.destroy
    @customer.destroy
  end

  test "no access if not logged in" do
    get :new
    assert_access_denied(true, false)
    get :show, :id => @customer.braintree_customer_id
    assert_access_denied(true, false)
    get :edit, :id => @customer.braintree_customer_id
    assert_access_denied(true, false)
  end


  test "should get new if logged in and not customer" do
    login @user
    get :new
    assert_not_nil assigns(:tr_data)
    assert_response :success
  end

  test "new should direct edit if user is already a customer" do
    login @other_user
    get :new
    assert_response :redirect
    assert_equal edit_customer_url(@customer.braintree_customer_id), response.header['Location']
  end


  test "show" do
    login @other_user
    # Below will fail, as when we go to fetch the customer data, Braintree::Customer.find(params[:id]) won't find the customer as it is a FakeBraintree customer.
    #get :show, :id => @customer.braintree_customer_id

  end

end