spree_recurring_order 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/Gemfile +6 -0
- data/LICENSE +26 -0
- data/README.md +40 -0
- data/Rakefile +15 -0
- data/app/assets/javascripts/admin/spree_recurring_order.js +1 -0
- data/app/assets/javascripts/store/spree_recurring_order.js +1 -0
- data/app/assets/stylesheets/admin/admin.scss +6 -0
- data/app/assets/stylesheets/admin/spree_recurring_order.css +4 -0
- data/app/assets/stylesheets/store/order_complete.css +8 -0
- data/app/assets/stylesheets/store/show_order.css +14 -0
- data/app/assets/stylesheets/store/spree_recurring_order.css +4 -0
- data/app/controllers/spree/admin/recurring_orders_controller.rb +11 -0
- data/app/controllers/spree/orders_controller_decorator.rb +10 -0
- data/app/controllers/spree/recurring_orders_controller.rb +32 -0
- data/app/models/spree/order_decorator.rb +5 -0
- data/app/models/spree/recurring_order.rb +36 -0
- data/app/overrides/add_recurring_order_form.rb +5 -0
- data/app/overrides/add_tab_to_admin_menu.rb +5 -0
- data/app/views/spree/admin/recurring_orders/index.html.erb +39 -0
- data/app/views/spree/admin/shared/_recurring_orders_tab.html.erb +1 -0
- data/app/views/spree/orders/_recurring_order_form.html.erb +16 -0
- data/app/views/spree/recurring_orders/new.html.erb +6 -0
- data/app/views/spree/recurring_orders/show.html.erb +14 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +7 -0
- data/db/migrate/20140204052508_create_recurring_orders_table.rb +10 -0
- data/lib/generators/spree_recurring_order/install/install_generator.rb +31 -0
- data/lib/spree_recurring_order/engine.rb +22 -0
- data/lib/spree_recurring_order/factories.rb +6 -0
- data/lib/spree_recurring_order.rb +2 -0
- data/spec/controllers/spree/admin/recurring_orders_controller_spec.rb +24 -0
- data/spec/controllers/spree/orders_controller_spec.rb +44 -0
- data/spec/controllers/spree/recurring_order_controller_spec.rb +70 -0
- data/spec/models/spree/recurring_order_spec.rb +60 -0
- data/spec/spec_helper.rb +83 -0
- data/spree_recurring_order.gemspec +31 -0
- metadata +241 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e31aea92275d38f02697dafbbe7af85671fff65
|
4
|
+
data.tar.gz: d67a7308522c80729b4c602a092bd1ceac06c944
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 522d03015e276c9a0bb0eefb1db427cfb70f49a49b1ba8f81b51c13ce35ab02cef3acc5429ca4b4c8a8ad57815d0e3c7a65eebe7ab5eb3592c87a11bc111b111
|
7
|
+
data.tar.gz: f7a4b1c93340f1d010e981c6a7fefaf95299853e976c7b95e6e71a7c192b60a90ad9026c786fc96ba055279bf6f1b5fdd90b53e3f95656609a9cbc32aefb103c
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2014 [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,40 @@
|
|
1
|
+
SpreeRecurringOrder
|
2
|
+
===================
|
3
|
+
|
4
|
+
Introduction goes here.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Add spree_recurring_order to your Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'spree_recurring_order'
|
13
|
+
```
|
14
|
+
|
15
|
+
Bundle your dependencies and run the installation generator:
|
16
|
+
|
17
|
+
```shell
|
18
|
+
bundle
|
19
|
+
bundle exec rails g spree_recurring_order:install
|
20
|
+
```
|
21
|
+
|
22
|
+
Testing
|
23
|
+
-------
|
24
|
+
|
25
|
+
Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
|
26
|
+
|
27
|
+
```shell
|
28
|
+
bundle
|
29
|
+
bundle exec rake test_app
|
30
|
+
bundle exec rspec spec
|
31
|
+
```
|
32
|
+
|
33
|
+
When testing your applications integration with this extension you may use it's factories.
|
34
|
+
Simply add this require statement to your spec_helper:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'spree_recurring_order/factories'
|
38
|
+
```
|
39
|
+
|
40
|
+
Copyright (c) 2014 [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_recurring_order'
|
14
|
+
Rake::Task['extension:test_app'].invoke
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require admin/spree_backend
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require store/spree_frontend
|
@@ -0,0 +1,14 @@
|
|
1
|
+
div#show_recurring_order {
|
2
|
+
text-align: center;
|
3
|
+
margin-left: 10%;
|
4
|
+
margin-right: 10%;
|
5
|
+
}
|
6
|
+
|
7
|
+
div#show_recurring_order .title, div#show_recurring_order .text {
|
8
|
+
margin-top: 30px;;
|
9
|
+
}
|
10
|
+
|
11
|
+
div#show_recurring_order fieldset.share {
|
12
|
+
margin-top: 60px;
|
13
|
+
}
|
14
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Spree
|
2
|
+
class RecurringOrdersController < Spree::StoreController
|
3
|
+
|
4
|
+
def create
|
5
|
+
original_order = Spree::Order.find(recurring_order_params[:original_order_id])
|
6
|
+
if original_order.recurring_order.nil?
|
7
|
+
@recurring_order = Spree::RecurringOrder.new
|
8
|
+
@recurring_order.orders << original_order
|
9
|
+
|
10
|
+
if @recurring_order.save
|
11
|
+
redirect_to(spree.recurring_order_url(@recurring_order.id))
|
12
|
+
else
|
13
|
+
render :new
|
14
|
+
end
|
15
|
+
else
|
16
|
+
flash[:notice] = "Hmmm... It seems like this order already has a recurring order associated with it. Please get in touch at hello@yourgrocer.com.au if you have any doubts about it"
|
17
|
+
redirect_to(order_url(original_order.number))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
@recurring_order = Spree::RecurringOrder.find(params[:id])
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def recurring_order_params
|
28
|
+
params[:recurring_order].permit(:original_order_id)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Spree
|
2
|
+
class RecurringOrder < ActiveRecord::Base
|
3
|
+
|
4
|
+
validate :at_least_one_order
|
5
|
+
|
6
|
+
has_many :orders
|
7
|
+
|
8
|
+
belongs_to :original_order, class_name: 'Spree::Order'
|
9
|
+
|
10
|
+
def self.create_from_order(order)
|
11
|
+
recurring_order = RecurringOrder.new
|
12
|
+
recurring_order.orders << order
|
13
|
+
recurring_order.save!
|
14
|
+
recurring_order
|
15
|
+
end
|
16
|
+
|
17
|
+
def original_order
|
18
|
+
@original_order ||= orders.sort_by{|order| order.created_at}.first
|
19
|
+
end
|
20
|
+
|
21
|
+
def email
|
22
|
+
original_order.email
|
23
|
+
end
|
24
|
+
|
25
|
+
def phone
|
26
|
+
original_order.ship_address.phone rescue ''
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def at_least_one_order
|
32
|
+
self.errors[:orders] << "cannot be empty" if orders.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<% content_for :page_title do %>
|
2
|
+
<%= Spree.t(:recurring_orders) %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<% if @recurring_orders.any? %>
|
6
|
+
<table class="index responsive" id="listing_orders" data-hook>
|
7
|
+
<colgroup>
|
8
|
+
<col style="width: 25%;">
|
9
|
+
<col style="width: 25%;">
|
10
|
+
<col style="width: 15%;">
|
11
|
+
<col style="width: 15%;">
|
12
|
+
<col style="width: 20%;">
|
13
|
+
</colgroup>
|
14
|
+
<thead>
|
15
|
+
<tr>
|
16
|
+
<th><%= Spree.t(:original_order_number, resource: I18n.t(:other, :scope => 'activerecord.attributes.spree/recurring_order')) %></th>
|
17
|
+
<th><%= Spree.t(:customer_email, resource: I18n.t(:other, :scope => 'activerecord.attributes.spree/recurring_order')) %></th>
|
18
|
+
<th><%= Spree.t(:customer_phone, resource: I18n.t(:other, :scope => 'activerecord.attributes.spree/recurring_order')) %></th>
|
19
|
+
<th><%= Spree.t(:active?, resource: I18n.t(:other, :scope => 'activerecord.attributes.spree/recurring_order')) %></th>
|
20
|
+
<th><%= Spree.t(:created_at, resource: I18n.t(:created_at, :scope => 'activerecord.attributes.spree/recurring_order')) %></th>
|
21
|
+
</tr>
|
22
|
+
</thead>
|
23
|
+
<tbody>
|
24
|
+
<% @recurring_orders.each do |order| %>
|
25
|
+
<tr class="<%= cycle('odd', 'even') %>">
|
26
|
+
<td class="align-center"><%= link_to order.original_order.number, edit_admin_order_path(order.original_order) %></td>
|
27
|
+
<td class="align-center"><%= mail_to order.email %></td>
|
28
|
+
<td class="align-center"><%= mail_to order.phone %></td>
|
29
|
+
<td class="align-center">YES</td>
|
30
|
+
<td class="align-center"><%= l (order.created_at).to_date %></td>
|
31
|
+
</tr>
|
32
|
+
<% end %>
|
33
|
+
</tbody>
|
34
|
+
</table>
|
35
|
+
<% else %>
|
36
|
+
<div class="alpha twelve columns no-objects-found">
|
37
|
+
<%= Spree.t(:no_recurring_orders_found, resource: I18n.t(:other, scope: 'activerecord.models.spree/recurring_order')) %>
|
38
|
+
</div>
|
39
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= tab :recurring_orders, {:icon => 'icon-refresh', :label => 'recurring'} %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%- if @present_recurring %>
|
2
|
+
<fieldset id='recurring_orders'>
|
3
|
+
|
4
|
+
<h2>
|
5
|
+
<%= "Thanks #{@order.ship_address.firstname}!" %>
|
6
|
+
</h2>
|
7
|
+
<h2>Would you like to make this process even easier next time?</h2>
|
8
|
+
<p>Sign up for a recurring order and we will get in touch so you don't have to worry about your groceries anymore.</p>
|
9
|
+
|
10
|
+
<%= form_for @recurring_order do |f| %>
|
11
|
+
<%= f.hidden_field :original_order_id, value: @order.id %>
|
12
|
+
<%= f.submit "Send me hassle-free groceries" %>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
</fieldset>
|
16
|
+
<% end %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<div id='show_recurring_order'>
|
2
|
+
<h1 class='title'>And that's all!</h1>
|
3
|
+
|
4
|
+
<h2 class='text'>
|
5
|
+
<%= "Grocery shopping just became much easier for you, #{@recurring_order.original_order.ship_address.firstname}." %>
|
6
|
+
</h2>
|
7
|
+
|
8
|
+
|
9
|
+
<h2 class='text'>
|
10
|
+
We are getting in touch to setup your recurring order,
|
11
|
+
so feel free to relax and think about all that time that you are going to have in your hands.
|
12
|
+
</h2>
|
13
|
+
|
14
|
+
</div>
|
data/bin/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_recurring_order/engine', __FILE__)
|
5
|
+
|
6
|
+
require 'rails/all'
|
7
|
+
require 'rails/engine/commands'
|
data/config/routes.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Spree::Core::Engine.routes.draw do
|
2
|
+
|
3
|
+
resource :recurring_orders, only: [:create]
|
4
|
+
get "/recurring_orders/:id", controller: 'recurring_orders', action: 'show', as: 'recurring_order'
|
5
|
+
|
6
|
+
get "admin/recurring_orders/", controller: 'admin/recurring_orders', action: 'index', as: 'admin_recurring_orders'
|
7
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SpreeRecurringOrder
|
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_recurring_order\n"
|
9
|
+
append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_recurring_order\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_stylesheets
|
13
|
+
inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_recurring_order\n", :before => /\*\//, :verbose => true
|
14
|
+
inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_recurring_order\n", :before => /\*\//, :verbose => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_migrations
|
18
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_recurring_order'
|
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,22 @@
|
|
1
|
+
module SpreeRecurringOrder
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_recurring_order'
|
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
|
+
config.to_prepare &method(:activate).to_proc
|
21
|
+
end
|
22
|
+
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_recurring_order/factories'
|
6
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Admin::RecurringOrdersController do
|
4
|
+
|
5
|
+
let(:user) { mock_model Spree::User, :last_incomplete_spree_order => nil, :has_spree_role? => true, :spree_api_key => 'fake' }
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
controller.stub :spree_current_user => user
|
9
|
+
controller.stub :check_authorization
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'index' do
|
13
|
+
|
14
|
+
it 'should get all recurring orders' do
|
15
|
+
orders = []
|
16
|
+
Spree::RecurringOrder.should_receive(:all).and_return(orders)
|
17
|
+
|
18
|
+
spree_get :index
|
19
|
+
assigns(:recurring_orders).should == orders
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::OrdersController do
|
4
|
+
|
5
|
+
let(:order) {double(Spree::Order)}
|
6
|
+
let(:recurring_order) {double(Spree::RecurringOrder)}
|
7
|
+
let(:user) { mock_model Spree::User, :last_incomplete_spree_order => nil, :has_spree_role? => true, :spree_api_key => 'fake' }
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
controller.stub :spree_current_user => user
|
11
|
+
controller.stub :check_authorization
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe 'show' do
|
16
|
+
|
17
|
+
before :each do
|
18
|
+
Spree::Order.stub(:find_by_number!).with("G2134").and_return(order)
|
19
|
+
Spree::RecurringOrder.stub(:new).and_return(recurring_order)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should assign order' do
|
23
|
+
spree_get :show, id: "G2134"
|
24
|
+
assigns(:order).should == order
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should assign recurring order' do
|
28
|
+
spree_get :show, id: "G2134"
|
29
|
+
assigns(:recurring_order).should == recurring_order
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should assign @present_recurring' do
|
33
|
+
spree_get :show, {id: "G2134", order_completed: true}
|
34
|
+
assigns(:present_recurring).should == true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should not assign @present_recurring if not present' do
|
38
|
+
spree_get :show, {id: "G2134"}
|
39
|
+
assigns(:present_recurring).should == false
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::RecurringOrdersController do
|
4
|
+
|
5
|
+
let(:original_order){ FactoryGirl.build(:order, id: 1, number: 'G1234') }
|
6
|
+
let(:orders){ [] }
|
7
|
+
let(:recurring_order){ double(Spree::RecurringOrder, save: true, id: 666, orders: orders).as_null_object }
|
8
|
+
let(:user) { mock_model Spree::User, :last_incomplete_spree_order => nil, :has_spree_role? => true, :spree_api_key => 'fake' }
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
controller.stub :spree_current_user => user
|
12
|
+
controller.stub :check_authorization
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'integration' do
|
16
|
+
|
17
|
+
it 'should create new recurring order (integration)' do
|
18
|
+
old_order = FactoryGirl.create(:order)
|
19
|
+
spree_post :create, recurring_order: {original_order_id: old_order.id}
|
20
|
+
Spree::RecurringOrder.last.original_order.should == old_order
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'create' do
|
26
|
+
|
27
|
+
before :each do
|
28
|
+
Spree::Order.stub(:find).with("1").and_return(original_order)
|
29
|
+
Spree::RecurringOrder.stub(:new).and_return(recurring_order)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
it 'should create new recurring order' do
|
34
|
+
orders.should_receive(:<<).with(original_order)
|
35
|
+
recurring_order.should_receive(:save).and_return(true)
|
36
|
+
|
37
|
+
spree_post :create, recurring_order: {original_order_id: 1}
|
38
|
+
response.should redirect_to("/recurring_orders/666")
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should render order complete if recurring order cant be saved' do
|
42
|
+
recurring_order.should_receive(:save).and_return(false)
|
43
|
+
|
44
|
+
spree_post :create, recurring_order: {original_order_id: 1}
|
45
|
+
response.should render_template(:new)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should render order complete if recurring order already exists' do
|
49
|
+
original_order.stub(:recurring_order).and_return(recurring_order)
|
50
|
+
spree_post :create, recurring_order: {original_order_id: 1}
|
51
|
+
response.should redirect_to("/orders/G1234")
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'show' do
|
57
|
+
|
58
|
+
before :each do
|
59
|
+
Spree::RecurringOrder.stub(:find).with("1").and_return(recurring_order)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should render' do
|
63
|
+
spree_post :show, id: 1
|
64
|
+
response.should render_template(:show)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::RecurringOrder do
|
4
|
+
|
5
|
+
describe 'create from order' do
|
6
|
+
|
7
|
+
it 'should create from original order' do
|
8
|
+
order = FactoryGirl.create(:order)
|
9
|
+
|
10
|
+
recurring_order = Spree::RecurringOrder.create_from_order(order)
|
11
|
+
recurring_order.id.should_not be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should set original order' do
|
15
|
+
order = FactoryGirl.create(:order)
|
16
|
+
|
17
|
+
recurring_order = Spree::RecurringOrder.create_from_order(order)
|
18
|
+
recurring_order.original_order.should == order
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'validation' do
|
24
|
+
|
25
|
+
it 'should have at least one order' do
|
26
|
+
recurring_order = Spree::RecurringOrder.new
|
27
|
+
recurring_order.should_not be_valid
|
28
|
+
recurring_order.errors[:orders].should_not be_empty
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should be valid with one order' do
|
32
|
+
order = FactoryGirl.build(:order)
|
33
|
+
recurring_order = Spree::RecurringOrder.new
|
34
|
+
recurring_order.orders << order
|
35
|
+
recurring_order.should be_valid
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'delegation' do
|
41
|
+
|
42
|
+
let(:ship_address){FactoryGirl.build(:address)}
|
43
|
+
let(:order){FactoryGirl.build(:order, ship_address: ship_address)}
|
44
|
+
|
45
|
+
before :each do
|
46
|
+
@recurring_order = Spree::RecurringOrder.new
|
47
|
+
@recurring_order.orders << order
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should delegate customer email to original order' do
|
51
|
+
@recurring_order.email.should == order.email
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should delegate customer phone to original order' do
|
55
|
+
@recurring_order.phone.should == order.ship_address.phone
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Run Coverage report
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter 'spec/dummy'
|
5
|
+
add_group 'Controllers', 'app/controllers'
|
6
|
+
add_group 'Helpers', 'app/helpers'
|
7
|
+
add_group 'Mailers', 'app/mailers'
|
8
|
+
add_group 'Models', 'app/models'
|
9
|
+
add_group 'Views', 'app/views'
|
10
|
+
add_group 'Libraries', 'lib'
|
11
|
+
end
|
12
|
+
|
13
|
+
# Configure Rails Environment
|
14
|
+
ENV['RAILS_ENV'] = 'test'
|
15
|
+
|
16
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
17
|
+
|
18
|
+
require 'rspec/rails'
|
19
|
+
require 'database_cleaner'
|
20
|
+
require 'ffaker'
|
21
|
+
|
22
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
23
|
+
# in spec/support/ and its subdirectories.
|
24
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
25
|
+
|
26
|
+
# Requires factories defined in spree_core
|
27
|
+
require 'spree/testing_support/factories'
|
28
|
+
require 'spree/testing_support/controller_requests'
|
29
|
+
require 'spree/testing_support/authorization_helpers'
|
30
|
+
require 'spree/testing_support/url_helpers'
|
31
|
+
|
32
|
+
# Requires factories defined in lib/spree_recurring_order/factories.rb
|
33
|
+
require 'spree_recurring_order/factories'
|
34
|
+
|
35
|
+
RSpec.configure do |config|
|
36
|
+
config.include FactoryGirl::Syntax::Methods
|
37
|
+
|
38
|
+
# == URL Helpers
|
39
|
+
#
|
40
|
+
# Allows access to Spree's routes in specs:
|
41
|
+
#
|
42
|
+
# visit spree.admin_path
|
43
|
+
# current_path.should eql(spree.products_path)
|
44
|
+
config.include Spree::TestingSupport::UrlHelpers
|
45
|
+
config.include Spree::TestingSupport::ControllerRequests
|
46
|
+
|
47
|
+
# == Mock Framework
|
48
|
+
#
|
49
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
50
|
+
#
|
51
|
+
# config.mock_with :mocha
|
52
|
+
# config.mock_with :flexmock
|
53
|
+
# config.mock_with :rr
|
54
|
+
config.mock_with :rspec
|
55
|
+
config.color = true
|
56
|
+
|
57
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
58
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
59
|
+
|
60
|
+
# Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
|
61
|
+
# to cleanup after each test instead. Without transactional fixtures set to false the records created
|
62
|
+
# to setup a test will be unavailable to the browser, which runs under a seperate server instance.
|
63
|
+
config.use_transactional_fixtures = false
|
64
|
+
|
65
|
+
# Ensure Suite is set to use transactions for speed.
|
66
|
+
config.before :suite do
|
67
|
+
DatabaseCleaner.strategy = :transaction
|
68
|
+
DatabaseCleaner.clean_with :truncation
|
69
|
+
end
|
70
|
+
|
71
|
+
# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
|
72
|
+
config.before :each do
|
73
|
+
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
|
74
|
+
DatabaseCleaner.start
|
75
|
+
end
|
76
|
+
|
77
|
+
# After each spec clean the database.
|
78
|
+
config.after :each do
|
79
|
+
DatabaseCleaner.clean
|
80
|
+
end
|
81
|
+
|
82
|
+
config.fail_fast = ENV['FAIL_FAST'] || false
|
83
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.platform = Gem::Platform::RUBY
|
4
|
+
s.name = 'spree_recurring_order'
|
5
|
+
s.version = '2.1.3'
|
6
|
+
s.summary = 'Add the option to create a recurring order'
|
7
|
+
s.description = ''
|
8
|
+
s.required_ruby_version = '>= 2.0.0'
|
9
|
+
|
10
|
+
s.author = 'Francisco Trindade'
|
11
|
+
s.email = 'frank.trindade@gmail.com'
|
12
|
+
s.homepage = 'http://blog.franktrindade.com'
|
13
|
+
|
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.1.3'
|
20
|
+
|
21
|
+
s.add_development_dependency 'capybara', '~> 2.1'
|
22
|
+
s.add_development_dependency 'coffee-rails'
|
23
|
+
s.add_development_dependency 'database_cleaner'
|
24
|
+
s.add_development_dependency 'factory_girl', '~> 4.2'
|
25
|
+
s.add_development_dependency 'ffaker'
|
26
|
+
s.add_development_dependency 'rspec-rails', '~> 2.13'
|
27
|
+
s.add_development_dependency 'sass-rails'
|
28
|
+
s.add_development_dependency 'selenium-webdriver'
|
29
|
+
s.add_development_dependency 'simplecov'
|
30
|
+
s.add_development_dependency 'sqlite3'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_recurring_order
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francisco Trindade
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: spree_core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.1.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: capybara
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coffee-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: database_cleaner
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: factory_girl
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ffaker
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.13'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.13'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sass-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: selenium-webdriver
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sqlite3
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: ''
|
168
|
+
email: frank.trindade@gmail.com
|
169
|
+
executables: []
|
170
|
+
extensions: []
|
171
|
+
extra_rdoc_files: []
|
172
|
+
files:
|
173
|
+
- .gitignore
|
174
|
+
- .rspec
|
175
|
+
- Gemfile
|
176
|
+
- LICENSE
|
177
|
+
- README.md
|
178
|
+
- Rakefile
|
179
|
+
- app/assets/javascripts/admin/spree_recurring_order.js
|
180
|
+
- app/assets/javascripts/store/spree_recurring_order.js
|
181
|
+
- app/assets/stylesheets/admin/admin.scss
|
182
|
+
- app/assets/stylesheets/admin/spree_recurring_order.css
|
183
|
+
- app/assets/stylesheets/store/order_complete.css
|
184
|
+
- app/assets/stylesheets/store/show_order.css
|
185
|
+
- app/assets/stylesheets/store/spree_recurring_order.css
|
186
|
+
- app/controllers/spree/admin/recurring_orders_controller.rb
|
187
|
+
- app/controllers/spree/orders_controller_decorator.rb
|
188
|
+
- app/controllers/spree/recurring_orders_controller.rb
|
189
|
+
- app/models/spree/order_decorator.rb
|
190
|
+
- app/models/spree/recurring_order.rb
|
191
|
+
- app/overrides/add_recurring_order_form.rb
|
192
|
+
- app/overrides/add_tab_to_admin_menu.rb
|
193
|
+
- app/views/spree/admin/recurring_orders/index.html.erb
|
194
|
+
- app/views/spree/admin/shared/_recurring_orders_tab.html.erb
|
195
|
+
- app/views/spree/orders/_recurring_order_form.html.erb
|
196
|
+
- app/views/spree/recurring_orders/new.html.erb
|
197
|
+
- app/views/spree/recurring_orders/show.html.erb
|
198
|
+
- bin/rails
|
199
|
+
- config/locales/en.yml
|
200
|
+
- config/routes.rb
|
201
|
+
- db/migrate/20140204052508_create_recurring_orders_table.rb
|
202
|
+
- lib/generators/spree_recurring_order/install/install_generator.rb
|
203
|
+
- lib/spree_recurring_order.rb
|
204
|
+
- lib/spree_recurring_order/engine.rb
|
205
|
+
- lib/spree_recurring_order/factories.rb
|
206
|
+
- spec/controllers/spree/admin/recurring_orders_controller_spec.rb
|
207
|
+
- spec/controllers/spree/orders_controller_spec.rb
|
208
|
+
- spec/controllers/spree/recurring_order_controller_spec.rb
|
209
|
+
- spec/models/spree/recurring_order_spec.rb
|
210
|
+
- spec/spec_helper.rb
|
211
|
+
- spree_recurring_order.gemspec
|
212
|
+
homepage: http://blog.franktrindade.com
|
213
|
+
licenses: []
|
214
|
+
metadata: {}
|
215
|
+
post_install_message:
|
216
|
+
rdoc_options: []
|
217
|
+
require_paths:
|
218
|
+
- lib
|
219
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - '>='
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: 2.0.0
|
224
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - '>='
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
229
|
+
requirements:
|
230
|
+
- none
|
231
|
+
rubyforge_project:
|
232
|
+
rubygems_version: 2.1.11
|
233
|
+
signing_key:
|
234
|
+
specification_version: 4
|
235
|
+
summary: Add the option to create a recurring order
|
236
|
+
test_files:
|
237
|
+
- spec/controllers/spree/admin/recurring_orders_controller_spec.rb
|
238
|
+
- spec/controllers/spree/orders_controller_spec.rb
|
239
|
+
- spec/controllers/spree/recurring_order_controller_spec.rb
|
240
|
+
- spec/models/spree/recurring_order_spec.rb
|
241
|
+
- spec/spec_helper.rb
|