Skip to content
This repository has been archived by the owner on Feb 27, 2021. It is now read-only.

Updating the master to be in sync with spree/spree master #65

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9d7273c
Updating the gems
Apr 7, 2014
4591490
Bumped to 2.4.0.beta
Jul 10, 2014
da9ed60
Updates pending_payments to unprocessed_payments to comply with refac…
Aug 20, 2014
bb7845e
Updating for changes in RSpec 3 and Spree 2.4
Oct 10, 2014
0699477
Updates for Spree 2.4
Oct 10, 2014
8f69c7c
All green. Passing Specs. Updates Order pending_payments to unprocess…
Oct 11, 2014
35ddbcd
Add action give store credits as percentage
Oct 11, 2014
a3e4902
Integrate to the checkout workflow the store credit as percentage
Oct 12, 2014
3d8cf63
Add admin view for give_store_credit_as_percentage with translations
Oct 12, 2014
5b237c2
Refactoring for not apply twice the store credit to the same order
Oct 12, 2014
a073c53
Update translations
Oct 13, 2014
dc22f79
Register give_store_credit_as_percentage as an action in the engine
Oct 13, 2014
8a62e39
FIX typo
Oct 13, 2014
0a48a4c
FIX for nil users and for reason translation
Oct 13, 2014
4d3828d
FIX persisting updates of order total after applying the adjustments
Oct 13, 2014
0d6968f
FIX setting preferred flat percentage for give store credits
Oct 13, 2014
e340e14
Spec for partial store credit payment
Oct 21, 2014
8b4764d
Update generator and specs
Oct 27, 2014
b3c8205
Updating the gems
Apr 7, 2014
41bd475
Updating for changes in Spree 2.4
Oct 10, 2014
0852f62
Update generator and specs
Oct 27, 2014
e9ec45f
Include adjustment type
Nov 24, 2014
08bcb65
Update engine and dev dependencies.
futhr Dec 7, 2014
37c01b5
Tweak Travis config and test ruby 2.1.x
futhr Dec 7, 2014
bc2ebf6
Use .add_routes instead.
futhr Dec 7, 2014
904d1ad
Update documentation.
futhr Dec 7, 2014
7ec576d
Add Guardfile.
futhr Dec 7, 2014
34e2112
Fixes :fr locale.
futhr Dec 7, 2014
ce81322
Build version with Gem::Version.new
futhr Dec 7, 2014
9d6e6e9
Refactor spec support.
futhr Dec 7, 2014
a7fd357
Add support config for Hound CI.
futhr Dec 7, 2014
fecc1fc
Update to more accurate spec syntax.
futhr Dec 7, 2014
95e9070
Replace hash-rockets and tweak inconsistent syntax
futhr Dec 7, 2014
261ea9c
Fixes some basic Rubocop offenses.
futhr Dec 7, 2014
b238d6c
Refactor feature specs and order spec.
futhr Dec 7, 2014
84e6d19
Minor improvement of admin layout.
futhr Dec 7, 2014
0bf5391
Config for master branch.
futhr Dec 7, 2014
31c90fc
Tweak order decorator.
futhr Dec 7, 2014
ce17694
Updating the gems
Apr 7, 2014
c659902
Bumped to 2.4.0.beta
Jul 10, 2014
23f6e60
Updating for changes in RSpec 3 and Spree 2.4
Oct 10, 2014
15a55ef
Updates for Spree 2.4
Oct 10, 2014
18ece9c
Update generator and specs
Oct 27, 2014
a190eb4
Include adjustment type
Nov 24, 2014
6019e9e
Changes in order
Jun 3, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
\#*
*~
.#*
.DS_Store
spec/dummy
Gemfile.lock
*.swp
.bundle
.rvmrc
coverage
.sass-cache
tmp
.ruby-version
.ruby-gemset
17 changes: 17 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# Too picky.
LineLength:
Enabled: false

# This should truly be on for well documented gems.
Documentation:
Enabled: false

# Neatly aligned code is too swell.
SingleSpaceBeforeFirstArg:
Enabled: false

# Don't mess with RSpec DSL.
Blocks:
Exclude:
- 'spec/**/*'
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--color
--format documentation
-r spec_helper
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
inherit_from: .hound.yml

AllCops:
Exclude:
- spec/dummy/**/*
- bin/*
- Guardfile
5 changes: 0 additions & 5 deletions .simplecov

This file was deleted.

15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
before_script:
- "sh -e /etc/init.d/xvfb start"
- "bundle exec rake test_app"
script: "DISPLAY=:99.0 bundle exec rspec spec"
---
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1
sudo: false
before_script:
- sh -e /etc/init.d/xvfb start
- export DISPLAY=:99.0
- bundle exec rake test_app
script:
- bundle exec rspec spec
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Contributing

In the spirit of [free software][1], **everyone** is encouraged to help improve this project.

Here are some ways *you* can contribute:

* by using prerelease versions
* by reporting [bugs][2]
* by suggesting new features
* by writing [translations][3]
* by writing or editing documentation
* by writing specifications
* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
* by refactoring code
* by resolving [issues][2]
* by reviewing patches

Issue/feature related questions can be asked thru [Gitter chat][4].

Starting point:

* Fork the repo
* Clone your repo
* Run `bundle install`
* Run `bundle exec rake test_app` to create the test application in `spec/test_app`
* Make your changes
* Ensure specs pass by running `bundle exec rspec spec`
* Submit your pull request

[1]: http://www.fsf.org/licensing/essays/free-sw.html
[2]: https://github.com/spree-contrib/spree_store_credits/issues
[3]: https://github.com/spree-contrib/spree_store_credits/blob/master/config/locales
[4]: https://gitter.im/spree-contrib/spree_store_credits
11 changes: 3 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
source 'https://rubygems.org'

group :development, :test do
gem 'spree_api', github: 'spree/spree', branch: 'master'
gem 'spree_core', github: 'spree/spree', branch: 'master'
gem 'spree_frontend', github: 'spree/spree', branch: 'master'
gem 'spree_backend', github: 'spree/spree', branch: 'master'
gem 'spree_sample', github: 'spree/spree', branch: 'master'
gem "spree_auth_devise", :github => 'spree/spree_auth_devise', :branch => 'master'
end
spree_version = 'master'
gem 'spree', github: 'spree/spree', branch: spree_version
gem "spree_auth_devise", github: 'spree/spree_auth_devise', branch: spree_version

gemspec
13 changes: 13 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
group :red_green_refactor, halt_on_fail: true do

guard :rspec, cmd: 'bundle exec rspec' do
watch('spec/spec_helper.rb') { 'spec' }
watch('config/routes.rb') { 'spec/controllers' }
watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.+)_decorator\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
end
end
17 changes: 10 additions & 7 deletions LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
Redistribution and use in source and binary forms, with or without modification,
Copyright (c) 2014 Roman Smirnov, Brian Quinn, and other contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the Rails Dog LLC nor the names of its
contributors may be used to endorse or promote products derived from this
* Neither the name of the Rails Dog LLC nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Expand All @@ -20,4 +23,4 @@ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 changes: 35 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
Spree Store Credits
===================
# Spree Store Credits

[![Build
Status](https://secure.travis-ci.org/spree/spree_store_credits.png)](http://travis-ci.org/spree/spree_store_credits)
[![Build Status](https://travis-ci.org/spree-contrib/spree_store_credits.svg?branch=master)](https://travis-ci.org/spree-contrib/spree_store_credits)
[![Code Climate](https://codeclimate.com/github/spree-contrib/spree_store_credits/badges/gpa.svg)](https://codeclimate.com/github/spree-contrib/spree_store_credits)

This Spree extension allows admins to issue arbitrary amounts of store credit to users. Users can redeem store credit during checkout, as part or full payment for an order. Also extends My Account page to display outstanding credit balance, and orders that used store credit.

This Spree extension allows admins to issue arbitrary amounts of store credit to users.
---

Users can redeem store credit during checkout, as part or full payment for an order.
## Installation

Also extends My Account page to display outstanding credit balance, and orders that used store credit.
Add spree_affiliate to your `Gemfile`:

Installation
============

1. Add the following to your applications Gemfile

gem 'spree_store_credits'

2. Run bundler

bundle install

3. Copy and execute migrations:
```ruby
gem 'spree_store_credits', github: 'spree-contrib/spree_store_credits', branch: 'master'
```

rails g spree_store_credits:install
Run:
```sh
bundle
bundle exec rails g spree_store_credits:install
```

---

Configuration
=============
## Configuration

By default Spree Store Credits does not require your order total to be above an amount to apply store credits.

Expand All @@ -43,3 +38,21 @@ Spree::StoreCredit.class_eval do
Spree::Config[:use_store_credit_minimum] = 0.01
end
```

---

## Contributing

See corresponding [guidelines][1]

---

## License

Copyright (c) 2014 [Roman Smirnov][2], [Brian Quinn][3], and other [contributors][4], released under the [New BSD License][5]

[1]: https://github.com/spree-contrib/spree_store_credits/blob/master/CONTRIBUTING.md
[2]: https://github.com/romul
[3]: https://github.com/BDQ
[4]: https://github.com/spree-contrib/spree_store_credits/graphs/contributors
[5]: https://github.com/spree-contrib/spree_store_credits/blob/master/LICENSE.md
18 changes: 5 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
require 'rake'
require 'rake/testtask'
require 'rake/packagetask'
require 'rubygems/package_task'
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'
require 'spree/testing_support/common_rake'

RSpec::Core::RakeTask.new

task :default => [:spec]

spec = eval(File.read('spree_store_credits.gemspec'))
task default: :spec

Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end

desc "Generates a dummy app for testing"
desc 'Generates a dummy app for testing'
task :test_app do
ENV['LIB_NAME'] = 'spree_store_credits'
Rake::Task['common:test_app'].invoke 'Spree::User'
end

1 change: 0 additions & 1 deletion app/assets/javascripts/admin/spree_store_credits.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require spree/backend
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require spree/frontend
1 change: 0 additions & 1 deletion app/assets/javascripts/store/spree_store_credits.js

This file was deleted.

3 changes: 0 additions & 3 deletions app/assets/stylesheets/admin/spree_store_credits.css

This file was deleted.

3 changes: 3 additions & 0 deletions app/assets/stylesheets/spree/backend/spree_store_credits.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*
*= require spree/backend
*/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/spree/frontend/spree_store_credits.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*
*= require spree/frontend
*/
3 changes: 0 additions & 3 deletions app/assets/stylesheets/store/spree_store_credits.css

This file was deleted.

20 changes: 10 additions & 10 deletions app/controllers/spree/admin/store_credits_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
module Spree
class Admin::StoreCreditsController < Admin::ResourceController
before_filter :check_amounts, :only => [:edit, :update]
prepend_before_filter :set_remaining_amount, :only => [:create, :update]
before_action :check_amounts, only: [:edit, :update]
prepend_before_filter :set_remaining_amount, only: [:create, :update]

protected
def permitted_resource_params
params.require(:store_credit).permit(permitted_store_credit_attributes)
end

def permitted_resource_params
params.require(:store_credit).permit(permitted_store_credit_attributes)
end

private

def check_amounts
if (@store_credit.remaining_amount < @store_credit.amount)
flash[:error] = Spree.t(:cannot_edit_used)
redirect_to spree.admin_store_credits_path
end
return unless @store_credit.remaining_amount < @store_credit.amount
flash[:error] = Spree.t(:cannot_edit_used)
redirect_to spree.admin_store_credits_path
end

def set_remaining_amount
Expand All @@ -28,6 +29,5 @@ def collection
def permitted_store_credit_attributes
[:user_id, :amount, :reason, :remaining_amount]
end

end
end
34 changes: 28 additions & 6 deletions app/controllers/spree/checkout_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,41 @@ module Spree
Spree::PermittedAttributes.checkout_attributes << attrib unless Spree::PermittedAttributes.checkout_attributes.include?(attrib)
end

def update
if @order.update_from_params(params, permitted_checkout_attributes, request.headers.env)
@order.temporary_address = !params[:save_user_address]
unless @order.next
flash[:error] = @order.errors.full_messages.join("\n")
puts "ERROR: #{@order.errors.inspect}"
redirect_to checkout_state_path(@order.state) and return
end

if @order.completed?
@current_order = nil
flash.notice = Spree.t(:order_processed_successfully)
flash['order_completed'] = true
redirect_to completion_route
else
redirect_to checkout_state_path(@order.state)
end
else
render :edit
end
end

private

def remove_payments_attributes_if_total_is_zero
load_order_with_lock

return unless params[:order] && params[:order][:store_credit_amount]
@order.decrement!(:state_lock_version) if params[:order][:state_lock_version]
parsed_credit = Spree::Price.new
parsed_credit.price = params[:order][:store_credit_amount]
store_credit_amount = [parsed_credit.price, spree_current_user.store_credits_total].min
if store_credit_amount >= (current_order.total + @order.store_credit_amount)
params[:order].delete(:source_attributes)
params.delete(:payment_source)
params[:order].delete(:payments_attributes)
end
return unless store_credit_amount >= (current_order.total + @order.store_credit_amount)
params[:order].delete(:source_attributes)
params.delete(:payment_source)
params[:order].delete(:payments_attributes)
end
end
end
9 changes: 9 additions & 0 deletions app/controllers/spree/orders_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Spree::OrdersController.class_eval do

after_action :fire_visited_path, only: :populate

def fire_visited_path
current_path = URI.parse(request.original_url).path
Spree::PromotionHandler::Page.new(current_order, current_path, try_spree_current_user).activate
end
end
4 changes: 2 additions & 2 deletions app/models/spree/adjustment_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Spree::Adjustment.class_eval do
scope :store_credits, lambda { where(:source_type => 'Spree::StoreCredit') }
end
scope :store_credits, -> { where(source_type: 'Spree::StoreCredit') }
end
2 changes: 1 addition & 1 deletion app/models/spree/app_configuration_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Spree::AppConfiguration.class_eval do
preference :use_store_credit_minimum, :decimal, :default => 0.0
preference :use_store_credit_minimum, :decimal, default: 0.0
end
Loading