spree-bank-transfer 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +6 -0
- data/LICENSE +26 -0
- data/README.md +49 -0
- data/Rakefile +15 -0
- data/Versionfile +11 -0
- data/app/assets/javascripts/admin/spree_bank_transfer.js +1 -0
- data/app/assets/javascripts/store/spree_bank_transfer.js +1 -0
- data/app/assets/stylesheets/admin/spree_bank_transfer.css +3 -0
- data/app/assets/stylesheets/store/spree_bank_transfer.css +3 -0
- data/app/controllers/spree/admin/banks_controller.rb +13 -0
- data/app/helpers/.DS_Store +0 -0
- data/app/helpers/spree/.DS_Store +0 -0
- data/app/helpers/spree/admin/banks_helper.rb +15 -0
- data/app/models/.DS_Store +0 -0
- data/app/models/spree/.DS_Store +0 -0
- data/app/models/spree/bank.rb +9 -0
- data/app/models/spree/payment_method/bank_transfer.rb +30 -0
- data/app/overrides/add_banks_to_admin_configuration_sidebar.rb +8 -0
- data/app/views/.DS_Store +0 -0
- data/app/views/spree/admin/banks/_form.html.erb +26 -0
- data/app/views/spree/admin/banks/edit.html.erb +2 -0
- data/app/views/spree/admin/banks/index.html.erb +35 -0
- data/app/views/spree/admin/banks/new.html.erb +13 -0
- data/app/views/spree/admin/banks/toggle_activation.js.erb +6 -0
- data/app/views/spree/admin/payments/source_forms/_banktransfer.html.erb +0 -0
- data/app/views/spree/admin/payments/source_views/_banktransfer.html.erb +0 -0
- data/app/views/spree/checkout/.DS_Store +0 -0
- data/app/views/spree/checkout/payment/_banktransfer.html.erb +14 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +8 -0
- data/db/migrate/20130717071443_create_table_bank.rb +11 -0
- data/db/migrate/20130717125312_add_index_on_active_on_spree_bank.rb +5 -0
- data/lib/generators/spree_bank_transfer/.DS_Store +0 -0
- data/lib/generators/spree_bank_transfer/install/install_generator.rb +31 -0
- data/lib/spree_bank_transfer.rb +2 -0
- data/lib/spree_bank_transfer/engine.rb +26 -0
- data/lib/spree_bank_transfer/factories.rb +6 -0
- data/script/rails +7 -0
- data/spec/controllers/spree/admin/banks_controller_spec.rb +79 -0
- data/spec/models/spree/bank_spec.rb +22 -0
- data/spec/models/spree/payment_method/bank_transfer_spec.rb +104 -0
- data/spec/spec_helper.rb +81 -0
- data/spree_bank_transfer.gemspec +21 -0
- metadata +107 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.DS_Store
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2013 [name of plugin creator]
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
* Neither the name Spree nor the names of its contributors may be used to
|
13
|
+
endorse or promote products derived from this software without specific
|
14
|
+
prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
SpreeBankTransfer
|
2
|
+
=================
|
3
|
+
|
4
|
+
This extension allows admin to provide bank transfer payment method to its users.
|
5
|
+
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
Add spree_bank_transfer to your Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'spree_bank_transfer'
|
14
|
+
```
|
15
|
+
|
16
|
+
Bundle your dependencies and run the installation generator:
|
17
|
+
|
18
|
+
```shell
|
19
|
+
bundle
|
20
|
+
bundle exec rails g spree_bank_transfer:install
|
21
|
+
```
|
22
|
+
|
23
|
+
Use
|
24
|
+
-------------
|
25
|
+
Login as Admin and create a new payment method with Spree::PaymentMethod::BankTransfer as provider class.
|
26
|
+
|
27
|
+
Create bank details under configuration/banks.
|
28
|
+
|
29
|
+
Checkout and select bank transfer payment method. Here, user can see the list of bank details.
|
30
|
+
|
31
|
+
Testing
|
32
|
+
-------
|
33
|
+
|
34
|
+
Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
|
35
|
+
|
36
|
+
```shell
|
37
|
+
bundle
|
38
|
+
bundle exec rake test_app
|
39
|
+
bundle exec rspec spec
|
40
|
+
```
|
41
|
+
|
42
|
+
When testing your applications integration with this extension you may use it's factories.
|
43
|
+
Simply add this require statement to your spec_helper:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'spree_bank_transfer/factories'
|
47
|
+
```
|
48
|
+
|
49
|
+
Copyright (c) 2013 [name of extension creator], released under the New BSD License
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'spree/testing_support/extension_rake'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
|
9
|
+
task :default => [:spec]
|
10
|
+
|
11
|
+
desc 'Generates a dummy app for testing'
|
12
|
+
task :test_app do
|
13
|
+
ENV['LIB_NAME'] = 'spree_bank_transfer'
|
14
|
+
Rake::Task['extension:test_app'].invoke
|
15
|
+
end
|
data/Versionfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file is used to designate compatibilty with different versions of Spree
|
2
|
+
# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
|
3
|
+
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
# '1.2.x' => { :branch => 'master' }
|
7
|
+
# '1.1.x' => { :branch => '1-1-stable' }
|
8
|
+
# '1.0.x' => { :branch => '1-0-stable' }
|
9
|
+
# '0.70.x' => { :branch => '0-70-stable' }
|
10
|
+
# '0.40.x' => { :tag => 'v1.0.0', :version => '1.0.0' }
|
11
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require admin/spree_backend
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require store/spree_frontend
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Spree
|
2
|
+
class PaymentMethod::BankTransfer < PaymentMethod
|
3
|
+
|
4
|
+
def actions
|
5
|
+
%w{capture void}
|
6
|
+
end
|
7
|
+
|
8
|
+
# Indicates whether its possible to capture the payment
|
9
|
+
def can_capture?(payment)
|
10
|
+
['checkout', 'pending'].include?(payment.state)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Indicates whether its possible to void the payment.
|
14
|
+
def can_void?(payment)
|
15
|
+
payment.state != 'void'
|
16
|
+
end
|
17
|
+
|
18
|
+
def capture(*args)
|
19
|
+
ActiveMerchant::Billing::Response.new(true, "", {}, {})
|
20
|
+
end
|
21
|
+
|
22
|
+
def void(*args)
|
23
|
+
ActiveMerchant::Billing::Response.new(true, "", {}, {})
|
24
|
+
end
|
25
|
+
|
26
|
+
def source_required?
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
:virtual_path => 'spree/admin/shared/_configuration_menu',
|
3
|
+
:name => 'add_banks_to_admin_configuration_sidebar',
|
4
|
+
:insert_bottom => "[data-hook='admin_configurations_sidebar_menu']",
|
5
|
+
:text => %q{
|
6
|
+
<%= configurations_sidebar_menu_item Spree.t(:banks), admin_banks_path %>
|
7
|
+
}
|
8
|
+
)
|
data/app/views/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @bank } %>
|
2
|
+
|
3
|
+
<%= form_for [:admin, @bank] do |f| %>
|
4
|
+
<div data-hook="admin_inside_bank_form" class="row">
|
5
|
+
<div class="alpha five columns">
|
6
|
+
<%= f.field_container :name do %>
|
7
|
+
<%= f.label :name, Spree.t(:name) %> <span class="required">*</span><br />
|
8
|
+
<%= f.error_message_on :name, :class => 'fullwidth title' %>
|
9
|
+
<%= f.text_field :name, :class => 'fullwidth' %>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<%= f.field_container :account_no do %>
|
13
|
+
<%= f.label :account_no, Spree.t(:account_no) %><span class="required">*</span><br />
|
14
|
+
<%= f.text_field :account_no, :class => 'fullwidth' %>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<%= f.field_container :active do %>
|
18
|
+
<%= f.check_box :active %>
|
19
|
+
<%= f.label :active, Spree.t(:active) %>
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
<%= f.submit %>
|
23
|
+
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
<% end %>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<%= render :partial => 'spree/admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<% content_for :page_title do %>
|
4
|
+
<%= Spree.t(:listing_banks) %>
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
<% content_for :page_actions do %>
|
8
|
+
<li>
|
9
|
+
<%= button_link_to Spree.t(:new_bank), new_admin_bank_path %>
|
10
|
+
</li>
|
11
|
+
<% end %>
|
12
|
+
|
13
|
+
<%= paginate @banks %>
|
14
|
+
|
15
|
+
<table class='index'>
|
16
|
+
<thead>
|
17
|
+
<tr>
|
18
|
+
<th>Name</th>
|
19
|
+
<th>Account No</th>
|
20
|
+
<th>Status</th>
|
21
|
+
</tr>
|
22
|
+
</thead>
|
23
|
+
|
24
|
+
<tbody>
|
25
|
+
<% @banks.each do |bank| %>
|
26
|
+
<tr class="<%= cycle('odd', 'even') %>">
|
27
|
+
<td class="align-center"><%= bank.name %></td>
|
28
|
+
<td class="align-center"><%= bank.account_no %></td>
|
29
|
+
<td class="align-center" id='active-status-<%= bank.id %>'><%= bank_status(bank) %></td>
|
30
|
+
<td class="actions"><%= link_to action_to_toggle_bank_status(bank), toggle_activation_admin_bank_path(bank), :remote => true, :method => :put %></td>
|
31
|
+
<td class="actions"><%= link_to_edit bank, :no_text => true, :class => 'edit' %></td>
|
32
|
+
</tr>
|
33
|
+
<% end %>
|
34
|
+
</tbody>
|
35
|
+
</table>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%= render :partial => 'spree/admin/shared/configuration_menu' %>
|
2
|
+
|
3
|
+
<% content_for :page_title do %>
|
4
|
+
<%= Spree.t(:new_bank) %>
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
<% content_for :page_actions do %>
|
8
|
+
<li>
|
9
|
+
<%= button_link_to Spree.t(:back_to_banks_list), admin_banks_path, :icon => 'icon-arrow-left' %>
|
10
|
+
</li>
|
11
|
+
<% end %>
|
12
|
+
|
13
|
+
<%= render :partial => 'form' %>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<% if @success %>
|
2
|
+
$('#active-status-<%= @bank.id %>').text('<%= bank_status(@bank) %>')
|
3
|
+
$('a[href="<%= toggle_activation_admin_bank_path(@bank) %>"]').text('<%= action_to_toggle_bank_status(@bank) %>')
|
4
|
+
<% else %>
|
5
|
+
alert('<%= @bank.errors.full_messages.to_sentence %>')
|
6
|
+
<% end %>
|
File without changes
|
File without changes
|
Binary file
|
data/config/routes.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateTableBank < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spree_banks do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :account_no
|
6
|
+
t.boolean :active, :default => true
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
add_index :spree_banks, [:name, :account_no], :unique => true
|
10
|
+
end
|
11
|
+
end
|
Binary file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SpreeBankTransfer
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
class_option :auto_run_migrations, :type => :boolean, :default => false
|
6
|
+
|
7
|
+
def add_javascripts
|
8
|
+
append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_bank_transfer\n"
|
9
|
+
append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_bank_transfer\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_stylesheets
|
13
|
+
inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_bank_transfer\n", :before => /\*\//, :verbose => true
|
14
|
+
inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_bank_transfer\n", :before => /\*\//, :verbose => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_migrations
|
18
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_bank_transfer'
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_migrations
|
22
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
|
23
|
+
if run_migrations
|
24
|
+
run 'bundle exec rake db:migrate'
|
25
|
+
else
|
26
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SpreeBankTransfer
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_bank_transfer'
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
8
|
+
|
9
|
+
# use rspec for tests
|
10
|
+
config.generators do |g|
|
11
|
+
g.test_framework :rspec
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.activate
|
15
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
16
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
initializer "spree.register.payment_methods" do |app|
|
21
|
+
app.config.spree.payment_methods << Spree::PaymentMethod::BankTransfer
|
22
|
+
end
|
23
|
+
|
24
|
+
config.to_prepare &method(:activate).to_proc
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
|
3
|
+
#
|
4
|
+
# Example adding this to your spec_helper will load these Factories for use:
|
5
|
+
# require 'spree_bank_transfer/factories'
|
6
|
+
end
|
data/script/rails
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
2
|
+
|
3
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
4
|
+
ENGINE_PATH = File.expand_path('../../lib/spree_bank_transfer/engine', __FILE__)
|
5
|
+
|
6
|
+
require 'rails/all'
|
7
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Admin::BanksController do
|
4
|
+
|
5
|
+
let(:role) { Spree::Role.create!(:name => 'user') }
|
6
|
+
let(:roles) { [role] }
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@user = mock_model(Spree::User, :generate_spree_api_key! => false)
|
10
|
+
@user.stub_chain(:roles, :includes).and_return([])
|
11
|
+
@user.stub(:has_spree_role?).with('admin').and_return(true)
|
12
|
+
controller.stub(:spree_user_signed_in?).and_return(true)
|
13
|
+
controller.stub(:spree_current_user).and_return(@user)
|
14
|
+
@user.stub(:roles).and_return(roles)
|
15
|
+
roles.stub(:includes).with(:permissions).and_return(roles)
|
16
|
+
controller.stub(:authorize_admin).and_return(true)
|
17
|
+
controller.stub(:authorize!).and_return(true)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "GET index" do
|
21
|
+
before(:each) do
|
22
|
+
@bank1 = mock_model(Spree::Bank)
|
23
|
+
Spree::Bank.stub(:page).and_return([@bank1])
|
24
|
+
end
|
25
|
+
|
26
|
+
def send_request
|
27
|
+
get :index, :use_route => 'spree'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "assigns @banks" do
|
31
|
+
send_request
|
32
|
+
assigns(:banks).should eq([@bank1])
|
33
|
+
end
|
34
|
+
|
35
|
+
it "paginates banks" do
|
36
|
+
Spree::Bank.should_receive(:page)
|
37
|
+
send_request
|
38
|
+
end
|
39
|
+
|
40
|
+
it "renders index template" do
|
41
|
+
send_request
|
42
|
+
response.should render_template(:index)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "PUT toggle_activation" do
|
47
|
+
before(:each) do
|
48
|
+
@bank = mock_model(Spree::Bank, :toggle! => true)
|
49
|
+
Spree::Bank.stub(:find).with("1").and_return(@bank)
|
50
|
+
end
|
51
|
+
|
52
|
+
def send_request
|
53
|
+
put :toggle_activation, :id => "1", :use_route => 'spree', :format => :js
|
54
|
+
end
|
55
|
+
|
56
|
+
it "toggles activation status of bank" do
|
57
|
+
@bank.should_receive(:toggle!).with(:active)
|
58
|
+
send_request
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when activation status toggled successfully" do
|
62
|
+
it "sets @success to true" do
|
63
|
+
send_request
|
64
|
+
assigns(:success).should be_true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when activation status not toggled successfully" do
|
69
|
+
before(:each) do
|
70
|
+
@bank.stub(:toggle!).and_return(false)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "sets @success to false" do
|
74
|
+
send_request
|
75
|
+
assigns(:success).should be_false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Bank do
|
4
|
+
it { should allow_mass_assignment_of :name }
|
5
|
+
it { should allow_mass_assignment_of :account_no }
|
6
|
+
it { should allow_mass_assignment_of :active }
|
7
|
+
it { should validate_presence_of :name }
|
8
|
+
it { should validate_presence_of :account_no }
|
9
|
+
it { should validate_uniqueness_of(:account_no).scoped_to(:name) }
|
10
|
+
|
11
|
+
describe ".active" do
|
12
|
+
before(:each) do
|
13
|
+
@active_bank1 = Spree::Bank.create! :name => 'bank1', :account_no => '98765'
|
14
|
+
@active_bank2 = Spree::Bank.create! :name => 'bank2', :account_no => '98765'
|
15
|
+
@bank3 = Spree::Bank.create! :name => 'bank3', :account_no => '98765', :active => false
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns active banks" do
|
19
|
+
Spree::Bank.active.should =~([@active_bank1, @active_bank2])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::PaymentMethod::BankTransfer do
|
4
|
+
before(:each) do
|
5
|
+
@order = Spree::Order.new
|
6
|
+
@payment_method = Spree::PaymentMethod::BankTransfer.create! :name => "Bank Transfer", :environment => Rails.env, :active => true
|
7
|
+
@payment = Spree::Payment.new :amount => 0.0
|
8
|
+
@payment.order = @order
|
9
|
+
@payment.payment_method = @payment_method
|
10
|
+
@payment.save!
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#actions" do
|
14
|
+
it "returns actions" do
|
15
|
+
@payment_method.actions.should eq(["capture", "void"])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#can_capture?" do
|
20
|
+
context "when payment state is pending or checkout" do
|
21
|
+
before(:each) do
|
22
|
+
@payment.state = 'checkout'
|
23
|
+
@payment.save!
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns true" do
|
27
|
+
@payment_method.can_capture?(@payment).should be_true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when payment state is pending" do
|
32
|
+
before(:each) do
|
33
|
+
@payment.state = 'pending'
|
34
|
+
@payment.save!
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns true" do
|
38
|
+
@payment_method.can_capture?(@payment).should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when payment state is not pending or checkout" do
|
44
|
+
before(:each) do
|
45
|
+
@payment.state = 'void'
|
46
|
+
@payment.save!
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns false" do
|
50
|
+
@payment_method.can_capture?(@payment).should be_false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#can_void?" do
|
56
|
+
context "when payment state is not void" do
|
57
|
+
before(:each) do
|
58
|
+
@payment.state = 'pending'
|
59
|
+
@payment.save!
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns true" do
|
63
|
+
@payment_method.can_void?(@payment).should be_true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when payment state is void" do
|
68
|
+
before(:each) do
|
69
|
+
@payment.update_column(:state, 'void')
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns false" do
|
73
|
+
@payment_method.can_void?(@payment).should be_false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#capture" do
|
79
|
+
it "creates a new active merchant billing response" do
|
80
|
+
ActiveMerchant::Billing::Response.should_receive(:new).with(true, "", {}, {})
|
81
|
+
@payment_method.capture
|
82
|
+
end
|
83
|
+
it "returns active merchant billing response" do
|
84
|
+
@payment_method.capture.should be_a(ActiveMerchant::Billing::Response)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#void" do
|
89
|
+
it "creates a new active merchant billing response" do
|
90
|
+
ActiveMerchant::Billing::Response.should_receive(:new).with(true, "", {}, {})
|
91
|
+
@payment_method.void
|
92
|
+
end
|
93
|
+
it "returns active merchant billing response" do
|
94
|
+
@payment_method.void.should be_a(ActiveMerchant::Billing::Response)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#source_required?" do
|
99
|
+
it "returns false" do
|
100
|
+
@payment_method.source_required?.should be_false
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Run Coverage report
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_group 'Controllers', 'app/controllers'
|
5
|
+
add_group 'Helpers', 'app/helpers'
|
6
|
+
add_group 'Mailers', 'app/mailers'
|
7
|
+
add_group 'Models', 'app/models'
|
8
|
+
add_group 'Views', 'app/views'
|
9
|
+
add_group 'Libraries', 'lib'
|
10
|
+
end
|
11
|
+
|
12
|
+
# Configure Rails Environment
|
13
|
+
ENV['RAILS_ENV'] = 'test'
|
14
|
+
|
15
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
16
|
+
|
17
|
+
require 'rspec/rails'
|
18
|
+
require 'database_cleaner'
|
19
|
+
require 'ffaker'
|
20
|
+
|
21
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
22
|
+
# in spec/support/ and its subdirectories.
|
23
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
24
|
+
|
25
|
+
# Requires factories defined in spree_core
|
26
|
+
require 'spree/testing_support/factories'
|
27
|
+
require 'spree/testing_support/controller_requests'
|
28
|
+
require 'spree/testing_support/authorization_helpers'
|
29
|
+
require 'spree/testing_support/url_helpers'
|
30
|
+
|
31
|
+
# Requires factories defined in lib/spree_bank_transfer/factories.rb
|
32
|
+
require 'spree_bank_transfer/factories'
|
33
|
+
|
34
|
+
RSpec.configure do |config|
|
35
|
+
config.include FactoryGirl::Syntax::Methods
|
36
|
+
|
37
|
+
# == URL Helpers
|
38
|
+
#
|
39
|
+
# Allows access to Spree's routes in specs:
|
40
|
+
#
|
41
|
+
# visit spree.admin_path
|
42
|
+
# current_path.should eql(spree.products_path)
|
43
|
+
config.include Spree::TestingSupport::UrlHelpers
|
44
|
+
|
45
|
+
# == Mock Framework
|
46
|
+
#
|
47
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
48
|
+
#
|
49
|
+
# config.mock_with :mocha
|
50
|
+
# config.mock_with :flexmock
|
51
|
+
# config.mock_with :rr
|
52
|
+
config.mock_with :rspec
|
53
|
+
config.color = true
|
54
|
+
|
55
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
56
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
57
|
+
|
58
|
+
# Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
|
59
|
+
# to cleanup after each test instead. Without transactional fixtures set to false the records created
|
60
|
+
# to setup a test will be unavailable to the browser, which runs under a seperate server instance.
|
61
|
+
config.use_transactional_fixtures = false
|
62
|
+
|
63
|
+
# Ensure Suite is set to use transactions for speed.
|
64
|
+
config.before :suite do
|
65
|
+
DatabaseCleaner.strategy = :transaction
|
66
|
+
DatabaseCleaner.clean_with :truncation
|
67
|
+
end
|
68
|
+
|
69
|
+
# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
|
70
|
+
config.before :each do
|
71
|
+
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
|
72
|
+
DatabaseCleaner.start
|
73
|
+
end
|
74
|
+
|
75
|
+
# After each spec clean the database.
|
76
|
+
config.after :each do
|
77
|
+
DatabaseCleaner.clean
|
78
|
+
end
|
79
|
+
|
80
|
+
config.fail_fast = ENV['FAIL_FAST'] || false
|
81
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.platform = Gem::Platform::RUBY
|
4
|
+
s.name = 'spree-bank-transfer'
|
5
|
+
s.version = '2.0.5'
|
6
|
+
s.summary = 'Creates bank transfer payment method'
|
7
|
+
s.description = 'This extension allows admin to provide bank transfer payment method to its users.'
|
8
|
+
s.required_ruby_version = '>= 1.9.3'
|
9
|
+
|
10
|
+
s.author = 'Mohit Bansal'
|
11
|
+
s.email = 'info@vinsol.com'
|
12
|
+
s.homepage = 'http://vinsol.com'
|
13
|
+
s.license = "MIT"
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
#s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.require_path = 'lib'
|
17
|
+
s.requirements << 'none'
|
18
|
+
|
19
|
+
s.add_dependency 'spree_core', '~> 2.0.3'
|
20
|
+
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree-bank-transfer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mohit Bansal
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: spree_core
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.3
|
30
|
+
description: This extension allows admin to provide bank transfer payment method to
|
31
|
+
its users.
|
32
|
+
email: info@vinsol.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- Versionfile
|
43
|
+
- app/assets/javascripts/admin/spree_bank_transfer.js
|
44
|
+
- app/assets/javascripts/store/spree_bank_transfer.js
|
45
|
+
- app/assets/stylesheets/admin/spree_bank_transfer.css
|
46
|
+
- app/assets/stylesheets/store/spree_bank_transfer.css
|
47
|
+
- app/controllers/spree/admin/banks_controller.rb
|
48
|
+
- app/helpers/.DS_Store
|
49
|
+
- app/helpers/spree/.DS_Store
|
50
|
+
- app/helpers/spree/admin/banks_helper.rb
|
51
|
+
- app/models/.DS_Store
|
52
|
+
- app/models/spree/.DS_Store
|
53
|
+
- app/models/spree/bank.rb
|
54
|
+
- app/models/spree/payment_method/bank_transfer.rb
|
55
|
+
- app/overrides/add_banks_to_admin_configuration_sidebar.rb
|
56
|
+
- app/views/.DS_Store
|
57
|
+
- app/views/spree/admin/banks/_form.html.erb
|
58
|
+
- app/views/spree/admin/banks/edit.html.erb
|
59
|
+
- app/views/spree/admin/banks/index.html.erb
|
60
|
+
- app/views/spree/admin/banks/new.html.erb
|
61
|
+
- app/views/spree/admin/banks/toggle_activation.js.erb
|
62
|
+
- app/views/spree/admin/payments/source_forms/_banktransfer.html.erb
|
63
|
+
- app/views/spree/admin/payments/source_views/_banktransfer.html.erb
|
64
|
+
- app/views/spree/checkout/.DS_Store
|
65
|
+
- app/views/spree/checkout/payment/_banktransfer.html.erb
|
66
|
+
- config/locales/en.yml
|
67
|
+
- config/routes.rb
|
68
|
+
- db/migrate/20130717071443_create_table_bank.rb
|
69
|
+
- db/migrate/20130717125312_add_index_on_active_on_spree_bank.rb
|
70
|
+
- lib/generators/spree_bank_transfer/.DS_Store
|
71
|
+
- lib/generators/spree_bank_transfer/install/install_generator.rb
|
72
|
+
- lib/spree_bank_transfer.rb
|
73
|
+
- lib/spree_bank_transfer/engine.rb
|
74
|
+
- lib/spree_bank_transfer/factories.rb
|
75
|
+
- script/rails
|
76
|
+
- spec/controllers/spree/admin/banks_controller_spec.rb
|
77
|
+
- spec/models/spree/bank_spec.rb
|
78
|
+
- spec/models/spree/payment_method/bank_transfer_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
- spree_bank_transfer.gemspec
|
81
|
+
homepage: http://vinsol.com
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.9.3
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements:
|
101
|
+
- none
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.25
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Creates bank transfer payment method
|
107
|
+
test_files: []
|