Skip to content

Commit

Permalink
Merge pull request #10 from deepakmahakale/rspec-3.1.0
Browse files Browse the repository at this point in the history
Rspec 3.1.0
  • Loading branch information
deepakmahakale committed Dec 18, 2016
2 parents bb442c5 + 56509f9 commit 1dc5d3c
Show file tree
Hide file tree
Showing 46 changed files with 413 additions and 63 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ coverage
Gemfile.lock

test/
spec/dummy/tmp
spec/dummy/log/*.log
spec/dummy/db/*.sqlite3
spec/dummy/db/schema.rb
spec/dummy/db/migrate/*.rb
spec/dummy/public/*
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: ruby
rvm:
- 2.1.0
- 2.2.0
- 2.3.0

before_script:
- cd spec/dummy && bundle exec rake railties:install:migrations
- RAILS_ENV=test bundle exec rake db:migrate
- cd ../..

script: 'bundle exec rspec'

cache: bundler

notifications:
recipients:
- [email protected]
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
[![Build Status](https://travis-ci.org/deepakmahakale/spree_purchase_order.svg?branch=master)](https://travis-ci.org/deepakmahakale/spree_purchase_order)

# Spree Purchase Order

Add Purchase Order payment method in Spree

## Installation

1. Add this line to your Gemfile:

gem 'spree_purchase_order'
```ruby
gem 'spree_purchase_order'
```

2. Install the gem using Bundler:

bundle install
```bash
bundle install
```

3. Copy & run migrations
```bash
bundle exec rails g spree_purchase_order:install
```

bundle exec rails g spree_purchase_order:install

3. Restart your server
4. Restart your server
22 changes: 10 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
Expand All @@ -10,24 +11,21 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'SpreePurchaseOrder'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('README.md')
rdoc.rdoc_files.include('lib/**/*.rb')
end

APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'

load 'rails/tasks/statistics.rake'

Bundler::GemHelper.install_tasks

require 'rake/testtask'
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end
require 'rspec/core'
require 'rspec/core/rake_task'

desc "Run all specs in spec directory (excluding plugin specs)"
RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')

task default: :test
task default: :spec
13 changes: 13 additions & 0 deletions app/assets/stylesheets/spree/backend/spree_purchase_order.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
*= require spree/backend
*/
.btn.action-complete {
color: #fff;
background-color: #7DB942;
border-color: #70a63b;
}
.btn.action-complete:hover {
color: #fff;
background-color: #649335;
border-color: #52792b;
}
.icon.icon-complete:before{
content: "\e013";
}
15 changes: 0 additions & 15 deletions app/models/spree/order_decorator.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/models/spree/payment_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Spree::Payment.class_eval do
has_one :purchase_order
scope :from_purchase_order, -> { where(source_type: 'Spree::PurchaseOrder') }

def po?
payment_method.type == 'Spree::PaymentMethod::PurchaseOrder'
source_type == 'Spree::PurchaseOrder'
end
end
26 changes: 8 additions & 18 deletions app/models/spree/payment_method/purchase_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,12 @@ def payment_source_class
Spree::PurchaseOrder
end

def actions
%w(complete void)
end

def can_complete?(payment)
%w(checkout pending).include?(payment.state)
end

def can_void?(payment)
payment.state != 'void'
end

def authorize(*args)
ActiveMerchant::Billing::Response.new(true, 'Purchase Order: Success', {}, {})
end

def complete(*)
ActiveMerchant::Billing::Response.new(true, 'Purchase Order: Success', {}, {})
simulated_successful_billing_response('Purchase Order: Success')
end

def void(*args)
ActiveMerchant::Billing::Response.new(true, '', {}, {})
simulated_successful_billing_response
end

def source_required?
Expand All @@ -35,5 +19,11 @@ def source_required?
def auto_capture?
false
end

private

def simulated_successful_billing_response(message = "")
ActiveMerchant::Billing::Response.new(true, message, {}, {})
end
end
end
19 changes: 17 additions & 2 deletions app/models/spree/purchase_order.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
module Spree
class PurchaseOrder < ActiveRecord::Base
has_one :payment, as: :source
class PurchaseOrder < Spree::Base
belongs_to :payment_method
has_many :payments, as: :source

validates_presence_of :po_number, :organization_name

def actions
%w(complete void)
end

# Indicates whether its possible to complete the payment
def can_complete?(payment)
payment.pending? || payment.checkout?
end

# Indicates whether its possible to void the payment.
def can_void?(payment)
!payment.failed? && !payment.void?
end
end
end
10 changes: 10 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
en:
spree:
purchase_order: Purchase order
activerecord:
models:
spree/purchase_order: Purchase order
attributes:
spree/purchase_order:
po_number: Number
organization_name: Organization name
5 changes: 0 additions & 5 deletions db/migrate/20160111163926_add_po_number_to_spree_payments.rb

This file was deleted.

5 changes: 4 additions & 1 deletion lib/spree_purchase_order/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ class Engine < ::Rails::Engine
config.autoload_paths << "#{config.root}/lib"

config.generators do |g|
g.test_framework :rspec
g.test_framework :rspec, fixture: false
g.fixture_replacement :factory_girl, dir: 'spec/factories'
g.assets false
g.helper false
end

def self.activate
Expand Down
2 changes: 1 addition & 1 deletion lib/spree_purchase_order/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SpreePurchaseOrder
VERSION = '3.1.0.beta'
VERSION = '3.1.0'
end
3 changes: 3 additions & 0 deletions spec/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require File.expand_path('../config/application', __FILE__)

Rails.application.load_tasks
Empty file.
1 change: 1 addition & 0 deletions spec/dummy/app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require_tree .
4 changes: 4 additions & 0 deletions spec/dummy/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
*= require_tree .
*= require_self
*/
3 changes: 3 additions & 0 deletions spec/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end
2 changes: 2 additions & 0 deletions spec/dummy/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
Empty file added spec/dummy/app/models/.keep
Empty file.
14 changes: 14 additions & 0 deletions spec/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Dummy</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
3 changes: 3 additions & 0 deletions spec/dummy/bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
4 changes: 4 additions & 0 deletions spec/dummy/bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 4 additions & 0 deletions spec/dummy/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
22 changes: 22 additions & 0 deletions spec/dummy/bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env ruby
require 'pathname'

# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)

Dir.chdir APP_ROOT do

puts "== Installing dependencies =="
system "gem install bundler --conservative"
system "bundle check || bundle install"

puts "\n== Preparing database =="
system "bin/rake db:setup"

puts "\n== Removing old logs and tempfiles =="
system "rm -f log/*"
system "rm -rf tmp/cache"

puts "\n== Restarting application server =="
system "touch tmp/restart.txt"
end
2 changes: 2 additions & 0 deletions spec/dummy/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
28 changes: 28 additions & 0 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require File.expand_path('../boot', __FILE__)

require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"

Bundler.require(*Rails.groups)
require "spree_purchase_order"

module Dummy
class Application < Rails::Application

config.to_prepare do
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end

Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end

config.active_record.raise_in_transactional_callbacks = true
end
end

5 changes: 5 additions & 0 deletions spec/dummy/config/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)

require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
8 changes: 8 additions & 0 deletions spec/dummy/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
default: &default
adapter: sqlite3
pool: 5
timeout: 5000

test:
<<: *default
database: db/test.sqlite3
3 changes: 3 additions & 0 deletions spec/dummy/config/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require File.expand_path('../application', __FILE__)

Rails.application.initialize!
13 changes: 13 additions & 0 deletions spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Rails.application.configure do
config.cache_classes = true
config.eager_load = false
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_dispatch.show_exceptions = false
config.action_controller.allow_forgery_protection = false
config.action_mailer.delivery_method = :test
config.active_support.test_order = :random
config.active_support.deprecation = :stderr
end
1 change: 1 addition & 0 deletions spec/dummy/config/initializers/assets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rails.application.config.assets.version = '1.0'
1 change: 1 addition & 0 deletions spec/dummy/config/initializers/cookies_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rails.application.config.action_dispatch.cookies_serializer = :json
1 change: 1 addition & 0 deletions spec/dummy/config/initializers/filter_parameter_logging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rails.application.config.filter_parameters += [:password]
1 change: 1 addition & 0 deletions spec/dummy/config/initializers/session_store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rails.application.config.session_store :cookie_store, key: '_dummy_session'
2 changes: 2 additions & 0 deletions spec/dummy/config/initializers/spree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Spree.config do |config|
end
3 changes: 3 additions & 0 deletions spec/dummy/config/initializers/wrap_parameters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
end
2 changes: 2 additions & 0 deletions spec/dummy/config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
en:
hello: "Hello world"
Loading

0 comments on commit 1dc5d3c

Please sign in to comment.