/
spec_helper.rb
151 lines (129 loc) · 4.41 KB
/
spec_helper.rb
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
#require 'shoulda/integrations/rspec2' # Add this line
require "authlogic/test_case"
#require 'shoulda'
require 'mocha'
require "email_spec"
require 'capybara/rspec'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
# Requires supporting files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
#Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
include Hadean::TruncateHelper
include Hadean::TestHelpers
include Authlogic::TestCase
include ActiveMerchant::Billing
Rails.logger.level = 4
RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# config.mock_with :rspec
config.include(EmailSpec::Helpers)
config.include(EmailSpec::Matchers)
config.before(:suite) { trunctate_unseeded }
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
# config.use_transactional_fixtures = true
config.use_transactional_fixtures = false
#config.logger = :stdout
#Product.configuration[:if] = false
config.before(:each) do
User.any_instance.stubs(:create_cim_profile).returns(true)
User.any_instance.stubs(:update_cim_profile).returns(true)
User.any_instance.stubs(:delete_cim_profile).returns(true)
PaymentProfile.any_instance.stubs(:create_payment_profile).returns(true)
PaymentProfile.any_instance.stubs(:update_payment_profile).returns(true)
PaymentProfile.any_instance.stubs(:delete_payment_profile).returns(true)
if defined?(Sunspot)
::Sunspot.session = ::Sunspot::Rails::StubSessionProxy.new(::Sunspot.session)
end
DatabaseCleaner.start
end
config.after(:each) do
if defined?(Sunspot)
::Sunspot.session = ::Sunspot.session.original_session
end
DatabaseCleaner.clean
end
end
def registered_user_factory
u = Factory.build(:user)
u.state = 'registered'
u
end
def registered_with_credit_user_factory
u = Factory.build(:user)
u.state = 'registered_with_credit'
u
end
#class ActionController::TestCase
# include Authlogic::TestCase
# #setup :activate_authlogic
#end
def with_solr
Product.configuration[:if] = 'true'
yield
Product.configuration[:if] = false
end
def credit_card_hash(options = {})
{ :number => '1',
:first_name => 'Johnny',
:last_name => 'Dee',
:month => '8',
:year => "#{ Time.now.year + 1 }",
:verification_value => '323',
:type => 'visa'
}.update(options)
end
def credit_card(options = {})
ActiveMerchant::Billing::CreditCard.new( credit_card_hash(options) )
end
# -------------Payment profile and payment could use this
def example_credit_card_params( params = {})
default = {
:first_name => 'First Name',
:last_name => 'Last Name',
:type => 'visa',
:number => '4111111111111111',
:month => '10',
:year => '2012',
:verification_value => '999'
}.merge( params )
specific = case gateway_name #SubscriptionConfig.gateway_name
when 'authorize_net_cim'
{
:type => 'visa',
:number => '4007000000027',
}
# 370000000000002 American Express Test Card
# 6011000000000012 Discover Test Card
# 4007000000027 Visa Test Card
# 4012888818888 second Visa Test Card
# 3088000000000017 JCB
# 38000000000006 Diners Club/ Carte Blanche
when 'bogus'
{
:type => 'bogus',
:number => '1',
}
else
{}
end
default.merge(specific).merge(params)
end
def successful_unstore_response
'transaction_id=d79410c91b4b31ba99f5a90558565df9&error_code=000&auth_response_text=Stored Card Data Deleted'
end