gimme_gimme 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +143 -0
- data/README.md +37 -0
- data/Rakefile +10 -0
- data/features/run_features.feature +40 -0
- data/features/step_definitions/rails_steps.rb +62 -0
- data/features/support/env.rb +2 -0
- data/features/support/file_helpers.rb +11 -0
- data/lib/generators/gimme_gimme/base.rb +17 -0
- data/lib/generators/gimme_gimme/install/install_generator.rb +34 -0
- data/lib/generators/gimme_gimme/install/templates/controllers/credit_cards_controller.rb +3 -0
- data/lib/generators/gimme_gimme/install/templates/create_gimme_gimme_tables.rb +29 -0
- data/lib/generators/gimme_gimme/install/templates/models/credit_card.rb +3 -0
- data/lib/generators/gimme_gimme/test_support/templates/factories/factories.rb +10 -0
- data/lib/generators/gimme_gimme/test_support/templates/support/fake_cim.rb +9 -0
- data/lib/generators/gimme_gimme/test_support/templates/testing/fake_cim_gateway.rb +15 -0
- data/lib/generators/gimme_gimme/test_support/templates/testing/fake_cim_server.rb +329 -0
- data/lib/generators/gimme_gimme/test_support/templates/testing/fake_cim_spec_helpers.rb +21 -0
- data/lib/generators/gimme_gimme/test_support/test_support_generator.rb +23 -0
- data/lib/gimme_gimme.rb +7 -0
- data/lib/gimme_gimme/cim_gateway.rb +16 -0
- data/lib/gimme_gimme/credit_card.rb +125 -0
- data/lib/gimme_gimme/credit_cards_controller.rb +18 -0
- data/lib/gimme_gimme/engine.rb +7 -0
- data/lib/gimme_gimme/user.rb +43 -0
- data/lib/gimme_gimme/version.rb +3 -0
- data/spec/environment.rb +94 -0
- data/spec/factories/clearance.rb +8 -0
- data/spec/models/credit_card_spec.rb +219 -0
- data/spec/models/user_spec.rb +20 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/testapp/config/routes.rb +4 -0
- metadata +226 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gimme_gimme (0.2)
|
5
|
+
activemerchant
|
6
|
+
clearance
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
abstract (1.0.0)
|
12
|
+
actionmailer (3.0.3)
|
13
|
+
actionpack (= 3.0.3)
|
14
|
+
mail (~> 2.2.9)
|
15
|
+
actionpack (3.0.3)
|
16
|
+
activemodel (= 3.0.3)
|
17
|
+
activesupport (= 3.0.3)
|
18
|
+
builder (~> 2.1.2)
|
19
|
+
erubis (~> 2.6.6)
|
20
|
+
i18n (~> 0.4)
|
21
|
+
rack (~> 1.2.1)
|
22
|
+
rack-mount (~> 0.6.13)
|
23
|
+
rack-test (~> 0.5.6)
|
24
|
+
tzinfo (~> 0.3.23)
|
25
|
+
activemerchant (1.9.0)
|
26
|
+
activesupport (>= 2.3.2)
|
27
|
+
braintree (>= 2.0.0)
|
28
|
+
builder (>= 2.0.0)
|
29
|
+
activemodel (3.0.3)
|
30
|
+
activesupport (= 3.0.3)
|
31
|
+
builder (~> 2.1.2)
|
32
|
+
i18n (~> 0.4)
|
33
|
+
activerecord (3.0.3)
|
34
|
+
activemodel (= 3.0.3)
|
35
|
+
activesupport (= 3.0.3)
|
36
|
+
arel (~> 2.0.2)
|
37
|
+
tzinfo (~> 0.3.23)
|
38
|
+
activeresource (3.0.3)
|
39
|
+
activemodel (= 3.0.3)
|
40
|
+
activesupport (= 3.0.3)
|
41
|
+
activesupport (3.0.3)
|
42
|
+
arel (2.0.6)
|
43
|
+
aruba (0.2.7)
|
44
|
+
background_process
|
45
|
+
cucumber (~> 0.10.0)
|
46
|
+
background_process (1.2)
|
47
|
+
bourne (1.0)
|
48
|
+
mocha (= 0.9.8)
|
49
|
+
braintree (2.10.2)
|
50
|
+
builder (>= 2.0.0)
|
51
|
+
builder (2.1.2)
|
52
|
+
clearance (0.12.0)
|
53
|
+
diesel (~> 0.1.4)
|
54
|
+
rails (>= 3.0)
|
55
|
+
cucumber (0.10.0)
|
56
|
+
builder (>= 2.1.2)
|
57
|
+
diff-lcs (~> 1.1.2)
|
58
|
+
gherkin (~> 2.3.2)
|
59
|
+
json (~> 1.4.6)
|
60
|
+
term-ansicolor (~> 1.0.5)
|
61
|
+
daemons (1.1.0)
|
62
|
+
diesel (0.1.5)
|
63
|
+
railties
|
64
|
+
diff-lcs (1.1.2)
|
65
|
+
erubis (2.6.6)
|
66
|
+
abstract (>= 1.0.0)
|
67
|
+
eventmachine (0.12.10)
|
68
|
+
factory_girl (1.3.2)
|
69
|
+
gherkin (2.3.2)
|
70
|
+
json (~> 1.4.6)
|
71
|
+
term-ansicolor (~> 1.0.5)
|
72
|
+
i18n (0.5.0)
|
73
|
+
json (1.4.6)
|
74
|
+
mail (2.2.12)
|
75
|
+
activesupport (>= 2.3.6)
|
76
|
+
i18n (>= 0.4.0)
|
77
|
+
mime-types (~> 1.16)
|
78
|
+
treetop (~> 1.4.8)
|
79
|
+
mime-types (1.16)
|
80
|
+
mocha (0.9.8)
|
81
|
+
rake
|
82
|
+
nokogiri (1.4.4)
|
83
|
+
polyglot (0.3.1)
|
84
|
+
rack (1.2.1)
|
85
|
+
rack-mount (0.6.13)
|
86
|
+
rack (>= 1.0.0)
|
87
|
+
rack-test (0.5.6)
|
88
|
+
rack (>= 1.0)
|
89
|
+
rails (3.0.3)
|
90
|
+
actionmailer (= 3.0.3)
|
91
|
+
actionpack (= 3.0.3)
|
92
|
+
activerecord (= 3.0.3)
|
93
|
+
activeresource (= 3.0.3)
|
94
|
+
activesupport (= 3.0.3)
|
95
|
+
bundler (~> 1.0)
|
96
|
+
railties (= 3.0.3)
|
97
|
+
railties (3.0.3)
|
98
|
+
actionpack (= 3.0.3)
|
99
|
+
activesupport (= 3.0.3)
|
100
|
+
rake (>= 0.8.7)
|
101
|
+
thor (~> 0.14.4)
|
102
|
+
rake (0.8.7)
|
103
|
+
rspec (2.3.0)
|
104
|
+
rspec-core (~> 2.3.0)
|
105
|
+
rspec-expectations (~> 2.3.0)
|
106
|
+
rspec-mocks (~> 2.3.0)
|
107
|
+
rspec-core (2.3.1)
|
108
|
+
rspec-expectations (2.3.0)
|
109
|
+
diff-lcs (~> 1.1.2)
|
110
|
+
rspec-mocks (2.3.0)
|
111
|
+
rspec-rails (2.3.1)
|
112
|
+
actionpack (~> 3.0)
|
113
|
+
activesupport (~> 3.0)
|
114
|
+
railties (~> 3.0)
|
115
|
+
rspec (~> 2.3.0)
|
116
|
+
shoulda (2.11.3)
|
117
|
+
sqlite3-ruby (1.3.2)
|
118
|
+
term-ansicolor (1.0.5)
|
119
|
+
thin (1.2.7)
|
120
|
+
daemons (>= 1.0.9)
|
121
|
+
eventmachine (>= 0.12.6)
|
122
|
+
rack (>= 1.0.0)
|
123
|
+
thor (0.14.6)
|
124
|
+
treetop (1.4.9)
|
125
|
+
polyglot (>= 0.3.1)
|
126
|
+
tzinfo (0.3.23)
|
127
|
+
|
128
|
+
PLATFORMS
|
129
|
+
ruby
|
130
|
+
|
131
|
+
DEPENDENCIES
|
132
|
+
aruba
|
133
|
+
bourne
|
134
|
+
cucumber
|
135
|
+
factory_girl
|
136
|
+
gimme_gimme!
|
137
|
+
nokogiri
|
138
|
+
rails (>= 3.0.3)
|
139
|
+
rake
|
140
|
+
rspec-rails (>= 2.3.1)
|
141
|
+
shoulda
|
142
|
+
sqlite3-ruby
|
143
|
+
thin
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Gimme, Gimme!
|
2
|
+
gimme_gimme is a Rails engine for managing a User's credit cards. It can
|
3
|
+
authorize and charge cards through its Authorize.net gateway.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
Important: gimme_gimme assumes that you are using Clearance. If you're not,
|
7
|
+
things will probably break.
|
8
|
+
|
9
|
+
gimme_gimme ships with generators:
|
10
|
+
|
11
|
+
rails generate gimme_gimme:install
|
12
|
+
|
13
|
+
This will create a DB migration and include the GimmeGimme::User module into
|
14
|
+
the User model.
|
15
|
+
|
16
|
+
To copy fake server and spec helper files to your
|
17
|
+
application, run:
|
18
|
+
|
19
|
+
rails generate gimme_gimme:test_support
|
20
|
+
|
21
|
+
|
22
|
+
gimme_gimme uses Authorize.net for its CIM (customer information management)
|
23
|
+
gateway. To set it up, create config/authorize_net.yml with the following
|
24
|
+
info:
|
25
|
+
|
26
|
+
|
27
|
+
test:
|
28
|
+
authorize_net_api_login_id: <Fill in login id>
|
29
|
+
authorize_net_transaction_key: <Fill in transaction key>
|
30
|
+
gateway_mode: 'test'
|
31
|
+
<rails_env>:
|
32
|
+
authorize_net_api_login_id: <Fill in login id>
|
33
|
+
authorize_net_transaction_key: <Fill in transaction key>
|
34
|
+
gateway_mode: <Choose a gateway mode>
|
35
|
+
|
36
|
+
gimme_gimme will use Rails.env to determine which entry in the YAML file to
|
37
|
+
use.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
@puts @announce @disable-bundler
|
2
|
+
Feature: Generators
|
3
|
+
|
4
|
+
Scenario: Successfully generate a gimme_gimme'd application
|
5
|
+
Given I successfully run "bundle exec rails new testapp"
|
6
|
+
And I cd to "testapp"
|
7
|
+
And I append to "Gemfile" with:
|
8
|
+
"""
|
9
|
+
gem "clearance"
|
10
|
+
gem "cucumber-rails"
|
11
|
+
gem "capybara"
|
12
|
+
gem "factory_girl_rails"
|
13
|
+
gem "dynamic_form"
|
14
|
+
gem "database_cleaner"
|
15
|
+
gem "formtastic"
|
16
|
+
gem "rspec-rails", :require => false
|
17
|
+
gem "database_cleaner"
|
18
|
+
gem "formtastic"
|
19
|
+
gem "rspec-rails", :require => false
|
20
|
+
"""
|
21
|
+
When I bootstrap the application for clearance
|
22
|
+
And I add the "gimme_gimme" gem from this project as a dependency
|
23
|
+
And I successfully run "bundle install"
|
24
|
+
And I successfully run "rails generate gimme_gimme:install"
|
25
|
+
And I successfully run "rails generate gimme_gimme:test_support"
|
26
|
+
And a file named "testapp/config/initializers/authorize_net.yml" with:
|
27
|
+
"""
|
28
|
+
test:
|
29
|
+
authorize_net_api_login_id: 'fake login id'
|
30
|
+
authorize_net_transaction_key: 'fake transaction key'
|
31
|
+
gateway_mode: 'test'
|
32
|
+
"""
|
33
|
+
And I successfully run "rake db:migrate"
|
34
|
+
When I run "rake"
|
35
|
+
Then it should pass with:
|
36
|
+
"""
|
37
|
+
passed
|
38
|
+
"""
|
39
|
+
Then the output should not contain "failed"
|
40
|
+
And the output should not contain "Could not find generator"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
When /^I add the "([^"]*)" gem from this project as a dependency$/ do |gem_name|
|
2
|
+
append_to_file('Gemfile', %{\ngem "#{gem_name}", :path => "#{PROJECT_ROOT}"})
|
3
|
+
end
|
4
|
+
|
5
|
+
When /^I bootstrap the application for clearance$/ do
|
6
|
+
steps %{
|
7
|
+
When I remove the file "public/index.html"
|
8
|
+
And I successfully run "rails generate cucumber:install"
|
9
|
+
And I successfully run "rails generate clearance:install"
|
10
|
+
And I successfully run "rails generate clearance:features"
|
11
|
+
And I configure ActionMailer to use "localhost" as a host
|
12
|
+
And I add flash messages to the layout
|
13
|
+
And I add session links to the layout
|
14
|
+
And I configure "clearance/sessions#new" as the root route
|
15
|
+
And I disable Capybara Javascript emulation
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
When /^I configure ActionMailer to use "([^"]+)" as a host$/ do |host|
|
20
|
+
mailer_config = "config.action_mailer.default_url_options = { :host => '#{host}' }"
|
21
|
+
replace_in_file "config/application.rb",
|
22
|
+
/(class .* < Rails::Application)/,
|
23
|
+
"\\1\n#{mailer_config}"
|
24
|
+
end
|
25
|
+
|
26
|
+
When /^I add flash messages to the layout$/ do
|
27
|
+
flashes = %{
|
28
|
+
<% flash.each do |key, value| -%>
|
29
|
+
<%= value %>
|
30
|
+
<% end -%>
|
31
|
+
}
|
32
|
+
|
33
|
+
replace_in_file "app/views/layouts/application.html.erb",
|
34
|
+
/(<body>)/,
|
35
|
+
"\\1\n#{flashes}"
|
36
|
+
end
|
37
|
+
|
38
|
+
When /^I add session links to the layout$/ do
|
39
|
+
links = %{
|
40
|
+
<% if signed_in? -%>
|
41
|
+
<%= link_to 'Sign out', sign_out_path, :method => :delete %>
|
42
|
+
<% else -%>
|
43
|
+
<%= link_to 'Sign in', sign_in_path %>
|
44
|
+
<% end -%>
|
45
|
+
}
|
46
|
+
|
47
|
+
replace_in_file "app/views/layouts/application.html.erb",
|
48
|
+
/(<body>)/,
|
49
|
+
"\\1\n#{links}"
|
50
|
+
end
|
51
|
+
|
52
|
+
When /^I configure "([^"]*)" as the root route$/ do |action|
|
53
|
+
replace_in_file "config/routes.rb",
|
54
|
+
/(routes\.draw do)/,
|
55
|
+
"\\1\nroot :to => '#{action}'"
|
56
|
+
end
|
57
|
+
|
58
|
+
When /^I disable Capybara Javascript emulation$/ do
|
59
|
+
replace_in_file "features/support/env.rb",
|
60
|
+
%{require 'cucumber/rails/capybara_javascript_emulation'},
|
61
|
+
"# Disabled"
|
62
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/base'
|
3
|
+
|
4
|
+
module GimmeGimme
|
5
|
+
module Generators
|
6
|
+
# Base generator for GimmeGimme generators. Setups up the source root.
|
7
|
+
class Base < ::Rails::Generators::Base
|
8
|
+
# @return [String] source root for tempates within a gimme_gimme generator
|
9
|
+
def self.source_root
|
10
|
+
@_gimme_gimme_source_root ||=
|
11
|
+
File.expand_path(File.join(File.dirname(__FILE__),
|
12
|
+
generator_name,
|
13
|
+
'templates'))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'generators/gimme_gimme/base'
|
2
|
+
require 'rails/generators/active_record/migration'
|
3
|
+
|
4
|
+
module GimmeGimme
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
extend ActiveRecord::Generators::Migration
|
9
|
+
|
10
|
+
desc <<DESC
|
11
|
+
Description:
|
12
|
+
Copy gimme_gimme files to your application.
|
13
|
+
DESC
|
14
|
+
|
15
|
+
def generate_migration
|
16
|
+
migration_template "create_gimme_gimme_tables.rb", "db/migrate/create_gimme_gimme_tables.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_models
|
20
|
+
directory "models", "app/models"
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_controllers
|
24
|
+
directory "controllers", "app/controllers"
|
25
|
+
end
|
26
|
+
|
27
|
+
def update_user_model
|
28
|
+
insert_into_file "app/models/user.rb",
|
29
|
+
"\ninclude GimmeGimme::User",
|
30
|
+
:after => "include Clearance::User"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class CreateGimmeGimmeTables < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :credit_cards do |t|
|
4
|
+
t.integer :user_id, :null => false
|
5
|
+
t.string :first_name, :null => false
|
6
|
+
t.string :last_name, :null => false
|
7
|
+
t.string :remote_customer_payment_profile_id, :null => false
|
8
|
+
t.integer :expiration_month, :null => false
|
9
|
+
t.integer :expiration_year, :null => false
|
10
|
+
t.string :last_four_digits, :limit => 4
|
11
|
+
t.string :card_type, :null => false
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
change_table :users do |t|
|
17
|
+
t.string :remote_customer_profile_id
|
18
|
+
t.string :customer_key
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.down
|
23
|
+
remove_table :credit_cards
|
24
|
+
change_table :users do |t|
|
25
|
+
t.remove :remote_customer_profile_id
|
26
|
+
t.remove :customer_key
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Factory.define :credit_card do |credit_card|
|
2
|
+
credit_card.association(:user)
|
3
|
+
credit_card.card_number { '4111111111111111' }
|
4
|
+
credit_card.first_name { 'Joe' }
|
5
|
+
credit_card.last_name { 'Shmoe' }
|
6
|
+
credit_card.expiration_month { '01' }
|
7
|
+
credit_card.expiration_year { '2015' }
|
8
|
+
credit_card.security_code { '123' }
|
9
|
+
credit_card.card_type { 'Visa' }
|
10
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require Rails.root.join('lib/gimme_gimme/testing/fake_cim_server')
|
2
|
+
require Rails.root.join('lib/gimme_gimme/testing/fake_cim_gateway')
|
3
|
+
|
4
|
+
$fake_cim_server = GimmeGimme::FakeCimServer.new
|
5
|
+
|
6
|
+
Before do
|
7
|
+
$fake_cim_server.reset
|
8
|
+
::GimmeGimme::CimGateway.instance.gateway = GimmeGimme::FakeCimGateway.new(:server => $fake_cim_server)
|
9
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module GimmeGimme
|
2
|
+
class FakeCimGateway < ActiveMerchant::Billing::AuthorizeNetCimGateway
|
3
|
+
def initialize(options = {})
|
4
|
+
@options = options.update(:login => 'fakelogin', :password => 'fakepassword')
|
5
|
+
end
|
6
|
+
|
7
|
+
def ssl_request(method, url, data, headers = {})
|
8
|
+
options[:server].request(method, url, data, headers)
|
9
|
+
end
|
10
|
+
|
11
|
+
def server
|
12
|
+
options[:server]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|