solidus_legacy_return_authorizations 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/LICENSE +26 -0
- data/README.md +62 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/solidus_legacy_return_authorizations.js +2 -0
- data/app/assets/stylesheets/spree/backend/solidus_legacy_return_authorizations.css +4 -0
- data/app/controllers/spree/admin/legacy_return_authorizations_controller.rb +25 -0
- data/app/controllers/spree/api/legacy_return_authorizations_controller.rb +74 -0
- data/app/helpers/spree/admin/navigation_helper_decorator.rb +12 -0
- data/app/helpers/spree/api/api_helpers_decorator.rb +7 -0
- data/app/models/spree/adjustment_decorator.rb +3 -0
- data/app/models/spree/inventory_unit_decorator.rb +3 -0
- data/app/models/spree/legacy_return_authorization.rb +108 -0
- data/app/models/spree/order_decorator.rb +3 -0
- data/app/models/spree/permission_sets/legacy_return_authorization_display.rb +9 -0
- data/app/models/spree/permission_sets/legacy_return_authorization_management.rb +9 -0
- data/app/models/spree/strong_parameters_decorator.rb +5 -0
- data/app/overrides/admin_legacy_return_authorizations.rb +14 -0
- data/app/views/spree/admin/legacy_return_authorizations/_form.html.erb +78 -0
- data/app/views/spree/admin/legacy_return_authorizations/edit.html.erb +32 -0
- data/app/views/spree/admin/legacy_return_authorizations/index.html.erb +48 -0
- data/app/views/spree/api/legacy_return_authorizations/index.v1.rabl +7 -0
- data/app/views/spree/api/legacy_return_authorizations/new.v1.rabl +3 -0
- data/app/views/spree/api/legacy_return_authorizations/show.v1.rabl +2 -0
- data/bin/rails +7 -0
- data/circle.yml +6 -0
- data/config/locales/en.yml +19 -0
- data/config/routes.rb +25 -0
- data/db/migrate/20140710044402_create_spree_legacy_return_authorizations.rb +26 -0
- data/lib/generators/solidus_legacy_return_authorizations/install/install_generator.rb +29 -0
- data/lib/solidus_legacy_return_authorizations.rb +2 -0
- data/lib/spree_legacy_return_authorizations/engine.rb +20 -0
- data/lib/spree_legacy_return_authorizations/factories.rb +13 -0
- data/solidus_legacy_return_authorizations.gemspec +29 -0
- data/spec/controllers/admin/legacy_return_authorizations_controller_spec.rb +32 -0
- data/spec/controllers/spree/api/legacy_return_authorizations_controller_spec.rb +157 -0
- data/spec/features/admin/orders/legacy_return_authorizations_spec.rb +26 -0
- data/spec/models/spree/legacy_return_authorization_spec.rb +214 -0
- data/spec/models/spree/permission_sets/legacy_return_authorization_display_spec.rb +22 -0
- data/spec/models/spree/permission_sets/legacy_return_authorization_management_spec.rb +20 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/support/authentication_support.rb +7 -0
- data/spec/support/have_attributes_matcher.rb +8 -0
- metadata +245 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
Deface::Override.new(
|
2
|
+
virtual_path: "spree/admin/shared/_order_submenu",
|
3
|
+
name: "admin_legacy_return_authorizations_submenu",
|
4
|
+
insert_bottom: "[data-hook='admin_order_tabs']",
|
5
|
+
text: %q(
|
6
|
+
<% if can? :display, Spree::LegacyReturnAuthorization %>
|
7
|
+
<% if @order.legacy_return_authorizations.exists? %>
|
8
|
+
<li<%== ' class="active"' if current == 'Legacy Return Authorizations' %>>
|
9
|
+
<%= link_to_with_icon 'share', Spree.t(:legacy_return_authorizations), admin_order_legacy_return_authorizations_url(@order) %>
|
10
|
+
</li>
|
11
|
+
<% end %>
|
12
|
+
<% end %>
|
13
|
+
)
|
14
|
+
)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
<div data-hook="admin_legacy_return_authorization_form_fields">
|
2
|
+
<table class="index">
|
3
|
+
<thead>
|
4
|
+
<tr data-hook="legacy_rma_header">
|
5
|
+
<th><%= Spree.t(:product) %></th>
|
6
|
+
<th><%= Spree.t(:quantity_shipped) %></th>
|
7
|
+
<th><%= Spree.t(:quantity_returned) %></th>
|
8
|
+
<th><%= Spree.t(:return_quantity) %></th>
|
9
|
+
</tr>
|
10
|
+
</thead>
|
11
|
+
<tbody>
|
12
|
+
<% @legacy_return_authorization.order.shipments.shipped.collect{|s| s.inventory_units.to_a}.flatten.group_by(&:variant).each do | variant, units| %>
|
13
|
+
<tr id="<%= dom_id(variant) %>" data-hook="legacy_rma_row" class="<%= cycle('odd', 'even')%>">
|
14
|
+
<td>
|
15
|
+
<div class="variant-name"><%= variant.name %></div>
|
16
|
+
<div class="variant-options"><%= variant.options_text %></div>
|
17
|
+
</td>
|
18
|
+
<td class="align-center"><%= units.select(&:shipped?).size %></td>
|
19
|
+
<td class="align-center"><%= units.select(&:returned?).size %></td>
|
20
|
+
<td class="return_quantity align-center">
|
21
|
+
<% if @legacy_return_authorization.received? %>
|
22
|
+
<%= @legacy_return_authorization.inventory_units.group_by(&:variant)[variant].try(:size) || 0 %>
|
23
|
+
<% elsif units.select(&:shipped?).empty? %>
|
24
|
+
0
|
25
|
+
<% else %>
|
26
|
+
<%= number_field_tag "return_quantity[#{variant.id}]",
|
27
|
+
@legacy_return_authorization.inventory_units.group_by(&:variant)[variant].try(:size) || 0, {:style => 'width:100px;', :min => 0} %>
|
28
|
+
<% end %>
|
29
|
+
</td>
|
30
|
+
</tr>
|
31
|
+
<% end %>
|
32
|
+
</tbody>
|
33
|
+
</table>
|
34
|
+
|
35
|
+
<%= f.field_container :amount do %>
|
36
|
+
<%= f.label :amount, Spree.t(:amount) %> <span class="required">*</span><br />
|
37
|
+
<% if @legacy_return_authorization.received? %>
|
38
|
+
<%= @legacy_return_authorization.display_amount %>
|
39
|
+
<% else %>
|
40
|
+
<%= f.text_field :amount, {:style => 'width:80px;'} %> <%= Spree.t(:legacy_rma_value) %>: <span id="legacy_rma_value">0.00</span>
|
41
|
+
<%= f.error_message_on :amount %>
|
42
|
+
<% end %>
|
43
|
+
<% end %>
|
44
|
+
|
45
|
+
<%= f.field_container :reason do %>
|
46
|
+
<%= f.label :reason, Spree.t(:reason) %>
|
47
|
+
<%= f.text_area :reason, {:style => 'height:100px;', :class => 'fullwidth'} %>
|
48
|
+
<%= f.error_message_on :reason %>
|
49
|
+
<% end %>
|
50
|
+
|
51
|
+
<%= f.field_container :stock_location do %>
|
52
|
+
<%= f.label :stock_location, Spree.t(:stock_location) %>
|
53
|
+
<%= f.select :stock_location_id, Spree::StockLocation.active.to_a.collect{|l|[l.name, l.id]}, {:style => 'height:100px;', :class => 'fullwidth'} %>
|
54
|
+
<%= f.error_message_on :reason %>
|
55
|
+
<% end %>
|
56
|
+
</div>
|
57
|
+
|
58
|
+
<script>
|
59
|
+
var line_item_prices = {};
|
60
|
+
<% @legacy_return_authorization.order.line_items.group_by(&:variant).each do | variant, items| %>
|
61
|
+
line_item_prices[<%= variant.id.to_s %>] = <%= items.first.price %>;
|
62
|
+
<% end %>
|
63
|
+
|
64
|
+
$(document).ready(function(){
|
65
|
+
var legacy_rma_amount = 0;
|
66
|
+
$("td.return_quantity input").on('change', function() {
|
67
|
+
var legacy_rma_amount = 0;
|
68
|
+
$.each($("td.return_quantity input"), function(i, input) {
|
69
|
+
var variant_id = $(input).prop('id').replace("return_quantity_", "");
|
70
|
+
legacy_rma_amount += line_item_prices[variant_id] * $(input).val()
|
71
|
+
});
|
72
|
+
|
73
|
+
if(!isNaN(legacy_rma_amount)){
|
74
|
+
$("span#legacy_rma_value").html(legacy_rma_amount.toFixed(2));
|
75
|
+
}
|
76
|
+
})
|
77
|
+
});
|
78
|
+
</script>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<% content_for :page_actions do %>
|
2
|
+
<li>
|
3
|
+
<% if @legacy_return_authorization.can_receive? %>
|
4
|
+
<%= button_link_to Spree.t(:receive), fire_admin_order_legacy_return_authorization_url(@order, @legacy_return_authorization, :e => 'receive'), :method => :put, :data => { :confirm => Spree.t(:are_you_sure) }, :icon => 'download-alt' %>
|
5
|
+
<% end %>
|
6
|
+
</li>
|
7
|
+
<li>
|
8
|
+
<% if @legacy_return_authorization.can_cancel? %>
|
9
|
+
<%= button_link_to Spree.t('actions.cancel'), fire_admin_order_legacy_return_authorization_url(@order, @legacy_return_authorization, :e => 'cancel'), :method => :put, :data => { :confirm => Spree.t(:are_you_sure) }, :icon => 'remove' %>
|
10
|
+
<% end %>
|
11
|
+
</li>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<%= render :partial => 'spree/admin/shared/order_tabs', :locals => { :current => 'Legacy Return Authorizations' } %>
|
15
|
+
|
16
|
+
<% content_for :page_title do %>
|
17
|
+
<i class="fa fa-arrow-right"></i> <%= Spree.t(:legacy_return_authorization) %> <%= @legacy_return_authorization.number %> (<%= Spree.t(@legacy_return_authorization.state.downcase) %>)
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
|
21
|
+
<%= render :partial => 'spree/shared/error_messages', :locals => { :target => @legacy_return_authorization } %>
|
22
|
+
<%= form_for [:admin, @order, @legacy_return_authorization] do |f| %>
|
23
|
+
<fieldset class="no-border-top">
|
24
|
+
<%= render :partial => 'form', :locals => { :f => f } %>
|
25
|
+
|
26
|
+
<div class="form-buttons filter-actions actions" data-hook="buttons">
|
27
|
+
<%= button Spree.t('actions.update'), 'repeat' %>
|
28
|
+
<span class="or"><%= Spree.t(:or) %></span>
|
29
|
+
<%= button_link_to Spree.t('actions.cancel'), admin_order_legacy_return_authorizations_url(@order), :icon => 'remove' %>
|
30
|
+
</div>
|
31
|
+
</fieldset>
|
32
|
+
<% end %>
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<%= render :partial => 'spree/admin/shared/order_tabs', :locals => { :current => 'Legacy Return Authorizations' } %>
|
2
|
+
|
3
|
+
<% content_for :page_actions do %>
|
4
|
+
<% if can?(:display, Spree::Order) %>
|
5
|
+
<li><%= button_link_to Spree.t(:back_to_orders_list), spree.admin_orders_path, :icon => 'arrow-left' %></li>
|
6
|
+
<% end %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<% content_for :page_title do %>
|
10
|
+
<i class="fa fa-arrow-right"></i> <%= Spree.t(:legacy_return_authorizations) %>
|
11
|
+
<% end %>
|
12
|
+
|
13
|
+
<% if @order.shipments.any?(&:shipped?) || @order.legacy_return_authorizations.any? %>
|
14
|
+
<table class="index">
|
15
|
+
<thead data-hook="legacy_rma_header">
|
16
|
+
<tr>
|
17
|
+
<th><%= Spree.t(:legacy_rma_number) %></th>
|
18
|
+
<th><%= Spree.t(:status) %></th>
|
19
|
+
<th><%= Spree.t(:amount) %></th>
|
20
|
+
<th><%= "#{Spree.t('date')}/#{Spree.t('time')}" %></th>
|
21
|
+
<th class="actions"></th>
|
22
|
+
</tr>
|
23
|
+
</thead>
|
24
|
+
<tbody>
|
25
|
+
<% @legacy_return_authorizations.each do |legacy_return_authorization| %>
|
26
|
+
<tr id="<%= spree_dom_id(legacy_return_authorization) %>" data-hook="legacy_rma_row" class="<%= cycle('odd', 'even')%>">
|
27
|
+
<td><%= legacy_return_authorization.number %></td>
|
28
|
+
<td><%= Spree.t(legacy_return_authorization.state.downcase) %></td>
|
29
|
+
<td><%= legacy_return_authorization.display_amount.to_html %></td>
|
30
|
+
<td><%= pretty_time(legacy_return_authorization.created_at) %></td>
|
31
|
+
<td class="actions">
|
32
|
+
<% if can?(:update, legacy_return_authorization) %>
|
33
|
+
<%= link_to_edit legacy_return_authorization, :no_text => true, :class => 'edit' %>
|
34
|
+
<% end %>
|
35
|
+
<% if can?(:destroy, legacy_return_authorization) && !legacy_return_authorization.received? %>
|
36
|
+
|
37
|
+
<%= link_to_delete legacy_return_authorization, :no_text => true %>
|
38
|
+
<% end %>
|
39
|
+
</td>
|
40
|
+
</tr>
|
41
|
+
<% end %>
|
42
|
+
</tbody>
|
43
|
+
</table>
|
44
|
+
<% else %>
|
45
|
+
<div data-hook="legacy_rma_cannont_create" class="no-objects-found">
|
46
|
+
<%= Spree.t(:cannot_create_returns) %>
|
47
|
+
</div>
|
48
|
+
<% end %>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
object false
|
2
|
+
child(@legacy_return_authorizations => :legacy_return_authorizations) do
|
3
|
+
attributes *legacy_return_authorization_attributes
|
4
|
+
end
|
5
|
+
node(:count) { @legacy_return_authorizations.count }
|
6
|
+
node(:current_page) { params[:page] || 1 }
|
7
|
+
node(:pages) { @legacy_return_authorizations.num_pages }
|
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_legacy_return_authorizations/engine', __FILE__)
|
5
|
+
|
6
|
+
require 'rails/all'
|
7
|
+
require 'rails/engine/commands'
|
data/circle.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Sample localization file for English. Add more files in this directory for other locales.
|
2
|
+
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
+
|
4
|
+
en:
|
5
|
+
activerecord:
|
6
|
+
attributes:
|
7
|
+
spree/legacy_return_authorization:
|
8
|
+
amount: Amount
|
9
|
+
models:
|
10
|
+
spree/legacy_return_authorization:
|
11
|
+
one: Legacy Return Authorization
|
12
|
+
other: Legacy Return Authorizations
|
13
|
+
spree:
|
14
|
+
legacy_return_authorization: Legacy Return Authorization
|
15
|
+
legacy_return_authorization_updated: Legacy Return authorization updated
|
16
|
+
legacy_return_authorizations: Legacy Return Authorizations
|
17
|
+
legacy_rma_credit: Legacy RMA Credit
|
18
|
+
legacy_rma_number: Legacy RMA Number
|
19
|
+
legacy_rma_value: Legacy RMA Value
|
data/config/routes.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Spree::Core::Engine.routes.draw do
|
2
|
+
namespace :api, defaults: { format: 'json' } do
|
3
|
+
concern :legacy_return_routes do
|
4
|
+
resources :legacy_return_authorizations, except: [:new, :create] do
|
5
|
+
member do
|
6
|
+
put :add
|
7
|
+
put :cancel
|
8
|
+
put :receive
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
resources :checkouts, only: [], concerns: :legacy_return_routes
|
13
|
+
resources :orders, only: [], concerns: :legacy_return_routes
|
14
|
+
end
|
15
|
+
|
16
|
+
namespace :admin do
|
17
|
+
resources :orders, except: [:show] do
|
18
|
+
resources :legacy_return_authorizations, except: [:new, :create] do
|
19
|
+
member do
|
20
|
+
put :fire
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class CreateSpreeLegacyReturnAuthorizations < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
# If this is a migrated database that had legacy returns in it then the table will already exist.
|
4
|
+
# But if this is a dev box, etc that's just including this extension then we need to create the table.
|
5
|
+
if !table_exists?(:spree_legacy_return_authorizations)
|
6
|
+
create_table :spree_legacy_return_authorizations do |t|
|
7
|
+
t.string "number"
|
8
|
+
t.string "state"
|
9
|
+
t.decimal "amount", precision: 10, scale: 2, default: 0.0, null: false
|
10
|
+
t.integer "order_id"
|
11
|
+
t.text "reason"
|
12
|
+
t.datetime "created_at"
|
13
|
+
t.datetime "updated_at"
|
14
|
+
t.integer "stock_location_id"
|
15
|
+
end
|
16
|
+
|
17
|
+
add_column :spree_inventory_units, :legacy_return_authorization_id, :integer
|
18
|
+
add_index :spree_inventory_units, :legacy_return_authorization_id
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def down
|
23
|
+
drop_table :spree_legacy_return_authorizations
|
24
|
+
remove_column :spree_inventory_units, :legacy_return_authorization_id
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SolidusLegacyReturnAuthorizations
|
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 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_legacy_return_authorizations\n"
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_stylesheets
|
12
|
+
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_legacy_return_authorizations\n", before: /\*\//, verbose: true
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_migrations
|
16
|
+
run 'bundle exec rake railties:install:migrations FROM=solidus_legacy_return_authorizations'
|
17
|
+
end
|
18
|
+
|
19
|
+
def run_migrations
|
20
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
|
21
|
+
if run_migrations
|
22
|
+
run 'bundle exec rake db:migrate'
|
23
|
+
else
|
24
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SpreeLegacyReturnAuthorizations
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'solidus_legacy_return_authorizations'
|
6
|
+
|
7
|
+
# use rspec for tests
|
8
|
+
config.generators do |g|
|
9
|
+
g.test_framework :rspec
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.activate
|
13
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
14
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
config.to_prepare &method(:activate).to_proc
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :legacy_return_authorization, class: Spree::LegacyReturnAuthorization do
|
3
|
+
number '100'
|
4
|
+
amount 100.00
|
5
|
+
association(:order, factory: :shipped_order)
|
6
|
+
reason 'no particular reason'
|
7
|
+
state 'received'
|
8
|
+
end
|
9
|
+
|
10
|
+
factory :new_legacy_return_authorization, class: Spree::LegacyReturnAuthorization do
|
11
|
+
association(:order, factory: :shipped_order)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.name = "solidus_legacy_return_authorizations"
|
6
|
+
s.version = "1.0.0"
|
7
|
+
s.summary = "Interfaces for Spree 2.3 Legacy Return Authorizations"
|
8
|
+
s.description = "Provides models and admin interfaces to interact with the LegacyReturnAuthorization models from Spree versions prior to 2.4"
|
9
|
+
s.required_ruby_version = ">= 2.1"
|
10
|
+
|
11
|
+
s.authors = ["Richard Nuno", "Jordan Brough"]
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.require_path = "lib"
|
16
|
+
s.requirements << "none"
|
17
|
+
|
18
|
+
s.add_dependency "solidus_core", [">= 1.0.0", "< 1.2.0"]
|
19
|
+
|
20
|
+
s.add_development_dependency "rspec-rails", "~> 3.2"
|
21
|
+
s.add_development_dependency "simplecov"
|
22
|
+
s.add_development_dependency "sqlite3"
|
23
|
+
s.add_development_dependency "sass-rails", "~> 4.0.2"
|
24
|
+
s.add_development_dependency "coffee-rails"
|
25
|
+
s.add_development_dependency "capybara", "~> 2.1"
|
26
|
+
s.add_development_dependency "factory_girl", "~> 4.4"
|
27
|
+
s.add_development_dependency "database_cleaner"
|
28
|
+
s.add_development_dependency "ffaker"
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Admin::LegacyReturnAuthorizationsController do
|
4
|
+
stub_authorization!
|
5
|
+
|
6
|
+
# Regression test for #1370 #3
|
7
|
+
let!(:legacy_return_authorization) { create(:legacy_return_authorization, reason: 'old reason') }
|
8
|
+
|
9
|
+
context "#update" do
|
10
|
+
let(:new_reason) { 'new reason' }
|
11
|
+
|
12
|
+
subject do
|
13
|
+
spree_put :update, {
|
14
|
+
id: legacy_return_authorization.to_param,
|
15
|
+
order_id: legacy_return_authorization.order.to_param,
|
16
|
+
legacy_return_authorization: {
|
17
|
+
:reason => new_reason,
|
18
|
+
},
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
before { subject }
|
23
|
+
|
24
|
+
it "redirects to legacy return authorizations index" do
|
25
|
+
expect(response).to redirect_to(spree.admin_order_legacy_return_authorizations_path(legacy_return_authorization.order))
|
26
|
+
end
|
27
|
+
|
28
|
+
it "updates the reason" do
|
29
|
+
expect(legacy_return_authorization.reload.reason).to eq new_reason
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe Api::LegacyReturnAuthorizationsController do
|
5
|
+
render_views
|
6
|
+
|
7
|
+
let!(:order) { create(:shipped_order) }
|
8
|
+
|
9
|
+
let(:product) { create(:product) }
|
10
|
+
let(:attributes) { [:id, :reason, :amount, :state] }
|
11
|
+
let(:resource_scoping) { { :order_id => order.to_param } }
|
12
|
+
|
13
|
+
before do
|
14
|
+
stub_api_controller_authentication!
|
15
|
+
end
|
16
|
+
|
17
|
+
context "as the order owner" do
|
18
|
+
before do
|
19
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
20
|
+
end
|
21
|
+
|
22
|
+
it "cannot see any legacy return authorizations" do
|
23
|
+
spree_get :index, order_id: order.to_param, format: :json
|
24
|
+
assert_unauthorized!
|
25
|
+
end
|
26
|
+
|
27
|
+
it "cannot see a single legacy return authorization" do
|
28
|
+
spree_get :show, order_id: order.to_param, :id => 1, format: :json
|
29
|
+
assert_unauthorized!
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "as an admin" do
|
34
|
+
before do
|
35
|
+
stub_api_controller_authentication!(admin: true)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "can show legacy return authorization" do
|
39
|
+
FactoryGirl.create(:legacy_return_authorization, :order => order)
|
40
|
+
legacy_return_authorization = order.legacy_return_authorizations.first
|
41
|
+
spree_get :show, :order_id => order.number, :id => legacy_return_authorization.id, format: :json
|
42
|
+
expect(response.status).to eq(200)
|
43
|
+
expect(json_response).to have_attributes(attributes)
|
44
|
+
expect(json_response["state"]).not_to be_blank
|
45
|
+
end
|
46
|
+
|
47
|
+
it "can get a list of legacy return authorizations" do
|
48
|
+
FactoryGirl.create(:legacy_return_authorization, :order => order)
|
49
|
+
FactoryGirl.create(:legacy_return_authorization, :order => order)
|
50
|
+
spree_get :index, :order_id => order.number, format: :json
|
51
|
+
expect(response.status).to eq(200)
|
52
|
+
legacy_return_authorizations = json_response["legacy_return_authorizations"]
|
53
|
+
expect(legacy_return_authorizations.first).to have_attributes(attributes)
|
54
|
+
expect(legacy_return_authorizations.first).not_to eq(legacy_return_authorizations.last)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'can control the page size through a parameter' do
|
58
|
+
FactoryGirl.create(:legacy_return_authorization, :order => order)
|
59
|
+
FactoryGirl.create(:legacy_return_authorization, :order => order)
|
60
|
+
spree_get :index, :order_id => order.number, :per_page => 1, format: :json
|
61
|
+
expect(json_response['count']).to eq(1)
|
62
|
+
expect(json_response['current_page']).to eq(1)
|
63
|
+
expect(json_response['pages']).to eq(2)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'can query the results through a parameter' do
|
67
|
+
FactoryGirl.create(:legacy_return_authorization, :order => order)
|
68
|
+
expected_result = create(:legacy_return_authorization, :reason => 'damaged')
|
69
|
+
order.legacy_return_authorizations << expected_result
|
70
|
+
spree_get :index, :q => { :reason_cont => 'damage' }, order_id: order.to_param, format: :json
|
71
|
+
expect(json_response['count']).to eq(1)
|
72
|
+
expect(json_response['legacy_return_authorizations'].first['reason']).to eq expected_result.reason
|
73
|
+
end
|
74
|
+
|
75
|
+
it "can update a legacy return authorization on the order" do
|
76
|
+
FactoryGirl.create(:legacy_return_authorization, :order => order)
|
77
|
+
legacy_return_authorization = order.legacy_return_authorizations.first
|
78
|
+
spree_put :update, :id => legacy_return_authorization.id, :legacy_return_authorization => { :amount => 19.99 }, format: :json, order_id: order.to_param
|
79
|
+
expect(response.status).to eq(200)
|
80
|
+
expect(json_response).to have_attributes(attributes)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "can add an inventory unit to a legacy return authorization on the order" do
|
84
|
+
FactoryGirl.create(:legacy_return_authorization, :order => order)
|
85
|
+
legacy_return_authorization = order.legacy_return_authorizations.first
|
86
|
+
inventory_unit = legacy_return_authorization.returnable_inventory.first
|
87
|
+
expect(inventory_unit).to be
|
88
|
+
expect(legacy_return_authorization.inventory_units).to be_empty
|
89
|
+
spree_put :add, :id => legacy_return_authorization.id, variant_id: inventory_unit.variant.id, quantity: 1, format: :json, order_id: order.to_param
|
90
|
+
expect(response.status).to eq(200)
|
91
|
+
expect(json_response).to have_attributes(attributes)
|
92
|
+
expect(legacy_return_authorization.reload.inventory_units).not_to be_empty
|
93
|
+
end
|
94
|
+
|
95
|
+
it "can mark a legacy return authorization as received on the order with an inventory unit" do
|
96
|
+
FactoryGirl.create(:new_legacy_return_authorization, :order => order, :stock_location_id => order.shipments.first.stock_location.id)
|
97
|
+
legacy_return_authorization = order.legacy_return_authorizations.first
|
98
|
+
expect(legacy_return_authorization.state).to eq("authorized")
|
99
|
+
|
100
|
+
# prep (use a rspec context or a factory instead?)
|
101
|
+
inventory_unit = legacy_return_authorization.returnable_inventory.first
|
102
|
+
expect(inventory_unit).to be
|
103
|
+
expect(legacy_return_authorization.inventory_units).to be_empty
|
104
|
+
spree_put :add, :id => legacy_return_authorization.id, variant_id: inventory_unit.variant.id, quantity: 1, format: :json, order_id: order.to_param
|
105
|
+
# end prep
|
106
|
+
|
107
|
+
spree_delete :receive, :id => legacy_return_authorization.id, format: :json, order_id: order.to_param
|
108
|
+
expect(response.status).to eq(200)
|
109
|
+
expect(legacy_return_authorization.reload.state).to eq("received")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "cannot mark a legacy return authorization as received on the order with no inventory units" do
|
113
|
+
FactoryGirl.create(:new_legacy_return_authorization, :order => order)
|
114
|
+
legacy_return_authorization = order.legacy_return_authorizations.first
|
115
|
+
expect(legacy_return_authorization.state).to eq("authorized")
|
116
|
+
spree_delete :receive, :id => legacy_return_authorization.id, format: :json, order_id: order.to_param
|
117
|
+
expect(response.status).to eq(422)
|
118
|
+
expect(legacy_return_authorization.reload.state).to eq("authorized")
|
119
|
+
end
|
120
|
+
|
121
|
+
it "can cancel a legacy return authorization on the order" do
|
122
|
+
FactoryGirl.create(:new_legacy_return_authorization, :order => order)
|
123
|
+
legacy_return_authorization = order.legacy_return_authorizations.first
|
124
|
+
expect(legacy_return_authorization.state).to eq("authorized")
|
125
|
+
spree_delete :cancel, :id => legacy_return_authorization.id, format: :json, order_id: order.to_param
|
126
|
+
expect(response.status).to eq(200)
|
127
|
+
expect(legacy_return_authorization.reload.state).to eq("canceled")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "can delete a legacy return authorization on the order" do
|
131
|
+
FactoryGirl.create(:legacy_return_authorization, :order => order)
|
132
|
+
legacy_return_authorization = order.legacy_return_authorizations.first
|
133
|
+
spree_delete :destroy, :id => legacy_return_authorization.id, format: :json, order_id: order.to_param
|
134
|
+
expect(response.status).to eq(204)
|
135
|
+
expect { legacy_return_authorization.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "as just another user" do
|
140
|
+
it "cannot update a legacy return authorization on the order" do
|
141
|
+
FactoryGirl.create(:legacy_return_authorization, :order => order)
|
142
|
+
legacy_return_authorization = order.legacy_return_authorizations.first
|
143
|
+
spree_put :update, :id => legacy_return_authorization.id, :legacy_return_authorization => { :amount => 19.99 }, format: :json, order_id: order.to_param
|
144
|
+
assert_unauthorized!
|
145
|
+
expect(legacy_return_authorization.reload.amount).not_to eq(19.99)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "cannot delete a legacy return authorization on the order" do
|
149
|
+
FactoryGirl.create(:legacy_return_authorization, :order => order)
|
150
|
+
legacy_return_authorization = order.legacy_return_authorizations.first
|
151
|
+
spree_delete :destroy, :id => legacy_return_authorization.id, format: :json, order_id: order.to_param
|
152
|
+
assert_unauthorized!
|
153
|
+
expect { legacy_return_authorization.reload }.not_to raise_error
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|