solidus_volume_pricing 0.2.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +35 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/dependabot.yml +7 -0
  5. data/.github/stale.yml +17 -0
  6. data/.gitignore +14 -9
  7. data/.rspec +2 -2
  8. data/.rubocop.yml +3 -7
  9. data/.rubocop_todo.yml +126 -0
  10. data/CHANGELOG.md +86 -0
  11. data/Gemfile +25 -2
  12. data/Guardfile +3 -1
  13. data/{LICENSE.md → LICENSE} +2 -2
  14. data/README.md +55 -50
  15. data/Rakefile +4 -19
  16. data/app/assets/javascripts/spree/backend/solidus_volume_pricing.js +1 -15
  17. data/app/controllers/spree/admin/volume_price_models_controller.rb +2 -1
  18. data/app/controllers/spree/admin/volume_prices_controller.rb +3 -1
  19. data/app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb +42 -0
  20. data/app/decorators/helpers/solidus_volume_pricing/spree/base_helper_decorator.rb +31 -0
  21. data/app/decorators/models/solidus_volume_pricing/spree/line_item_decorator.rb +18 -0
  22. data/app/decorators/models/solidus_volume_pricing/spree/variant_decorator.rb +21 -0
  23. data/app/models/solidus_volume_pricing/price_display.rb +47 -0
  24. data/app/models/solidus_volume_pricing/pricer.rb +95 -0
  25. data/app/models/solidus_volume_pricing/pricing_options.rb +20 -0
  26. data/app/models/spree/volume_price.rb +43 -26
  27. data/app/models/spree/volume_price_model.rb +6 -4
  28. data/app/overrides/spree/admin/shared/_settings_sub_menu/add_volume_price_model_admin_menu_links.html.erb.deface +5 -0
  29. data/app/overrides/views_decorator.rb +2 -0
  30. data/app/views/spree/admin/shared/_vp_product_tab.html.erb +2 -2
  31. data/app/views/spree/admin/variants/_edit_fields.html.erb +5 -32
  32. data/app/views/spree/admin/variants/volume_prices.html.erb +9 -36
  33. data/app/views/spree/admin/volume_price_models/_form.html.erb +6 -2
  34. data/app/views/spree/admin/volume_price_models/_list.html.erb +8 -4
  35. data/app/views/spree/admin/volume_price_models/_select.html.erb +17 -0
  36. data/app/views/spree/admin/volume_price_models/edit.html.erb +7 -6
  37. data/app/views/spree/admin/volume_price_models/index.html.erb +7 -5
  38. data/app/views/spree/admin/volume_price_models/new.html.erb +5 -5
  39. data/app/views/spree/admin/volume_prices/_table.html.erb +26 -0
  40. data/app/views/spree/admin/volume_prices/_volume_price_fields.html.erb +10 -8
  41. data/app/views/spree/products/_volume_pricing.html.erb +8 -8
  42. data/bin/console +17 -0
  43. data/bin/rails +12 -4
  44. data/bin/setup +8 -0
  45. data/config/locales/de.yml +17 -3
  46. data/config/locales/en.yml +21 -2
  47. data/config/locales/pt.yml +6 -2
  48. data/config/locales/ru.yml +6 -2
  49. data/config/locales/sv.yml +6 -2
  50. data/config/locales/tr.yml +6 -2
  51. data/config/routes.rb +3 -1
  52. data/db/migrate/20081119145604_create_volume_prices.rb +3 -1
  53. data/db/migrate/20110203174010_change_display_name_for_volume_prices.rb +3 -1
  54. data/db/migrate/20111206173307_prefix_volume_pricing_table_names.rb +3 -1
  55. data/db/migrate/20121115043422_add_discount_type_column.rb +3 -1
  56. data/db/migrate/20150513200904_add_role_to_volume_price.rb +3 -1
  57. data/db/migrate/20150603143015_create_spree_volume_price_models.rb +3 -1
  58. data/lib/generators/solidus_volume_pricing/install/install_generator.rb +5 -5
  59. data/lib/solidus_volume_pricing/engine.rb +16 -24
  60. data/lib/solidus_volume_pricing/range_from_string.rb +36 -0
  61. data/lib/solidus_volume_pricing/testing_support/factories.rb +14 -0
  62. data/lib/solidus_volume_pricing/version.rb +3 -16
  63. data/lib/solidus_volume_pricing.rb +6 -1
  64. data/solidus_volume_pricing.gemspec +26 -23
  65. data/spec/controllers/spree/admin/variants_controller_spec.rb +18 -15
  66. data/spec/features/manage_volume_price_models_feature_spec.rb +5 -7
  67. data/spec/features/manage_volume_prices_feature_spec.rb +9 -8
  68. data/spec/helpers/base_helper_spec.rb +3 -1
  69. data/spec/lib/solidus_volume_pricing/range_from_string_spec.rb +61 -0
  70. data/spec/models/solidus_volume_pricing/pricer_spec.rb +669 -0
  71. data/spec/models/solidus_volume_pricing/pricing_options_spec.rb +57 -0
  72. data/spec/models/spree/line_item_spec.rb +23 -21
  73. data/spec/models/spree/order_spec.rb +4 -2
  74. data/spec/models/spree/variant_spec.rb +3 -303
  75. data/spec/models/spree/volume_price_spec.rb +145 -50
  76. data/spec/spec_helper.rb +15 -35
  77. data/spec/support/shoulda.rb +11 -0
  78. metadata +83 -161
  79. data/.hound.yml +0 -40
  80. data/.travis.yml +0 -12
  81. data/CONTRIBUTING.md +0 -81
  82. data/app/controllers/spree/admin/variants_controller_decorator.rb +0 -32
  83. data/app/helpers/spree/base_helper_decorator.rb +0 -19
  84. data/app/models/spree/line_item_decorator.rb +0 -13
  85. data/app/models/spree/user_decorator.rb +0 -10
  86. data/app/models/spree/variant_decorator.rb +0 -104
  87. data/app/overrides/spree/admin/shared/sub_menu/_configuration/add_volume_price_model_admin_menu_links.html.erb.deface +0 -3
  88. data/app/views/spree/admin/volume_prices/_edit_fields.html.erb +0 -31
  89. data/spec/factories/volume_price_factory.rb +0 -12
  90. data/spec/support/capybara.rb +0 -12
  91. data/spec/support/database_cleaner.rb +0 -21
  92. data/spec/support/factory_girl.rb +0 -7
  93. data/spec/support/spree.rb +0 -10
@@ -6,10 +6,10 @@
6
6
  <td>
7
7
  <%= error_message_on(f.object, :discount_type) %>
8
8
  <%= f.select :discount_type, [
9
- ["#{Spree.t(:total_price)}", 'price'],
10
- ["#{Spree.t(:percent_discount)}", 'percent'],
11
- ["#{Spree.t(:price_discount)}", 'dollar']
12
- ], { include_blank: true }, class: 'select2' %>
9
+ [t('spree.total_price'), 'price'],
10
+ [t('spree.percent_discount'), 'percent'],
11
+ [t('spree.price_discount'), 'dollar']
12
+ ], { include_blank: true }, class: 'custom-select' %>
13
13
  </td>
14
14
  <td>
15
15
  <%= error_message_on(f.object, :range) %>
@@ -25,9 +25,11 @@
25
25
  </td>
26
26
  <td>
27
27
  <%= error_message_on(f.object, :role_id) %>
28
- <%= f.collection_select(:role_id, Spree::Role.all, :id, :name, { include_blank: Spree.t('match_choices.none') }, { class: 'select2' }) %>
29
- </td>
30
- <td class="actions">
31
- <%= link_to_remove_fields Spree.t(:remove), f, no_text: true %>
28
+ <%= f.collection_select(:role_id, Spree::Role.all, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select' }) %>
32
29
  </td>
30
+ <% if f.object.persisted? %>
31
+ <td class="actions">
32
+ <%= link_to_delete f.object, url: admin_volume_price_url(f.object.id), no_text: true %>
33
+ </td>
34
+ <% end %>
33
35
  </tr>
@@ -1,15 +1,15 @@
1
1
  <% display_percent ||= false %>
2
2
  <% if product.price > 0 and product.master.volume_prices.present? %>
3
3
  <div id="bulk-discount">
4
- <h6><%= Spree.t(:bulk_discount) %></h6>
4
+ <h6><%= t('spree.bulk_discount') %></h6>
5
5
  <table class="table">
6
- <% product.master.volume_prices.each do |v| %>
7
- <%= content_tag(:tr) do %>
8
- <%= content_tag :td, (v.open_ended? ? v.range : "#{v.range.to_range.begin}–#{v.range.to_range.end}") %>
9
- <%= content_tag :td, Spree::Money.new(v.amount).to_s %>
10
- <%= content_tag(:td, '%i%' % ((1.0 - v.amount / product.master.price) * 100.0).round) if display_percent %>
11
- <% end %>
12
- <% end %>
6
+ <% product.master.volume_prices.each do |v| %>
7
+ <%= content_tag(:tr) do %>
8
+ <%= content_tag :td, v.display_range %>
9
+ <%= content_tag :td, Spree::Money.new(v.amount).to_s %>
10
+ <%= content_tag(:td, '%i%' % ((1.0 - v.amount / product.master.price) * 100.0).round) if display_percent %>
11
+ <% end %>
12
+ <% end %>
13
13
  </table>
14
14
  </div>
15
15
  <% end %>
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "bundler/setup"
6
+ require "solidus_volume_pricing"
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+ $LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ IRB.start(__FILE__)
data/bin/rails CHANGED
@@ -1,7 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
- ENGINE_PATH = File.expand_path('../../lib/solidus_volume_pricing/engine', __FILE__)
3
+ # frozen_string_literal: true
5
4
 
6
- require 'rails/all'
7
- require 'rails/engine/commands'
5
+ app_root = 'spec/dummy'
6
+
7
+ unless File.exist? "#{app_root}/bin/rails"
8
+ system "bin/rake", app_root or begin # rubocop:disable Style/AndOr
9
+ warn "Automatic creation of the dummy app failed"
10
+ exit 1
11
+ end
12
+ end
13
+
14
+ Dir.chdir app_root
15
+ exec 'bin/rails', *ARGV
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+ bundle update
8
+ bundle exec rake clobber
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  de:
3
3
  spree:
4
- add_volume_price: Neuen Staffelpreis
4
+ add_volume_price: Neuer Staffelpreis
5
5
  position: Position
6
6
  discount_type:
7
7
  range: Bereich
@@ -10,9 +10,23 @@ de:
10
10
  price_discount:
11
11
  percent_discount:
12
12
  bulk_discount:
13
+ admin:
14
+ tab:
15
+ volume_price_models: Staffelpreismodelle
13
16
  activerecord:
17
+ models:
18
+ spree/volume_price:
19
+ one: Staffelpreis
20
+ other: Staffelpreise
21
+ spree/volume_price_model:
22
+ one: Staffelpreismodell
23
+ other: Staffelpreismodelle
14
24
  errors:
25
+ models:
26
+ spree/volume_price:
27
+ attributes:
28
+ discount_type:
29
+ inclusion: '%{value} ist kein valider Staffelpreistyp'
15
30
  messages:
16
- could_not_conver_to_range:
17
- is_not_a_valid_volume_price_type:
31
+ could_not_convert_to_range:
18
32
  must_be_in_format:
@@ -5,14 +5,33 @@ en:
5
5
  position: Position
6
6
  discount_type: Discount Type
7
7
  range: Range
8
+ role: Role
8
9
  volume_prices: Volume Prices
10
+ volume_price_model: Volume Price Model
11
+ new_volume_price_model: New Volume Price Model
12
+ volume_price_model_edit: Edit Volume Price Model
9
13
  volume_pricing: Volume Pricing
10
14
  price_discount: Price Discount
11
15
  percent_discount: Percent Discount
12
16
  bulk_discount: Bulk Discount
17
+ total_price: Total price
18
+ admin:
19
+ tab:
20
+ volume_price_models: Volume Price Models
13
21
  activerecord:
22
+ models:
23
+ spree/volume_price:
24
+ one: Volume Price
25
+ other: Volume Prices
26
+ spree/volume_price_model:
27
+ one: Volume Price Model
28
+ other: Volume Price Models
14
29
  errors:
30
+ models:
31
+ spree/volume_price:
32
+ attributes:
33
+ discount_type:
34
+ inclusion: '%{value} is not a valid Volume Price Type'
15
35
  messages:
16
- could_not_conver_to_range: "Couldn't convert to Range: %{number}"
17
- is_not_a_valid_volume_price_type: '%{value} is not a valid Volume Price Type'
36
+ could_not_convert_to_range: "Couldn't convert to Range: %{range_string}"
18
37
  must_be_in_format: 'must be in one of the following formats: (a..b), (a...b), (a+)'
@@ -12,7 +12,11 @@ pt:
12
12
  bulk_discount: Desconto por Quantidade
13
13
  activerecord:
14
14
  errors:
15
+ models:
16
+ spree/volume_price:
17
+ attributes:
18
+ discount_type:
19
+ inclusion: '%{value} is not a valid Volume Price Type'
15
20
  messages:
16
- could_not_conver_to_range:
17
- is_not_a_valid_volume_price_type:
21
+ could_not_convert_to_range:
18
22
  must_be_in_format:
@@ -12,7 +12,11 @@ ru:
12
12
  bulk_discount:
13
13
  activerecord:
14
14
  errors:
15
+ models:
16
+ spree/volume_price:
17
+ attributes:
18
+ discount_type:
19
+ inclusion: '%{value} is not a valid Volume Price Type'
15
20
  messages:
16
- could_not_conver_to_range:
17
- is_not_a_valid_volume_price_type:
21
+ could_not_convert_to_range:
18
22
  must_be_in_format:
@@ -12,7 +12,11 @@ sv:
12
12
  bulk_discount: Bulk rabatt
13
13
  activerecord:
14
14
  errors:
15
+ models:
16
+ spree/volume_price:
17
+ attributes:
18
+ discount_type:
19
+ inclusion: '%{value} är inte en giltligt typ för volympris'
15
20
  messages:
16
- could_not_conver_to_range: "Det gick inte att konvertera till omfång: %{number}"
17
- is_not_a_valid_volume_price_type: '%{value} är inte en giltligt typ för volympris'
21
+ could_not_convert_to_range: "Det gick inte att konvertera till omfång: %{range_string}"
18
22
  must_be_in_format: 'måste vara i ett av följande format: (a..b), (a...b), (a+)'
@@ -12,7 +12,11 @@ tr:
12
12
  bulk_discount:
13
13
  activerecord:
14
14
  errors:
15
+ models:
16
+ spree/volume_price:
17
+ attributes:
18
+ discount_type:
19
+ inclusion: '%{value} is not a valid Volume Price Type'
15
20
  messages:
16
- could_not_conver_to_range:
17
- is_not_a_valid_volume_price_type:
21
+ could_not_convert_to_range:
18
22
  must_be_in_format:
data/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
- Spree::Core::Engine.add_routes do
1
+ # frozen_string_literal: true
2
+
3
+ Spree::Core::Engine.routes.draw do
2
4
  namespace :admin do
3
5
  resources :products do
4
6
  resources :variants do
@@ -1,4 +1,6 @@
1
- class CreateVolumePrices < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class CreateVolumePrices < ActiveRecord::Migration[4.2]
2
4
  def self.up
3
5
  create_table :volume_prices do |t|
4
6
  t.references :variant
@@ -1,4 +1,6 @@
1
- class ChangeDisplayNameForVolumePrices < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class ChangeDisplayNameForVolumePrices < ActiveRecord::Migration[4.2]
2
4
  def self.up
3
5
  rename_column :volume_prices, :display, :name
4
6
  end
@@ -1,4 +1,6 @@
1
- class PrefixVolumePricingTableNames < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class PrefixVolumePricingTableNames < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  rename_table :volume_prices, :spree_volume_prices unless Spree::VolumePrice.table_exists?
4
6
  end
@@ -1,4 +1,6 @@
1
- class AddDiscountTypeColumn < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class AddDiscountTypeColumn < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_column :spree_volume_prices, :discount_type, :string
4
6
  end
@@ -1,4 +1,6 @@
1
- class AddRoleToVolumePrice < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class AddRoleToVolumePrice < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  add_column :spree_volume_prices, :role_id, :integer
4
6
  end
@@ -1,4 +1,6 @@
1
- class CreateSpreeVolumePriceModels < ActiveRecord::Migration
1
+ # frozen_string_literal: true
2
+
3
+ class CreateSpreeVolumePriceModels < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  create_table :spree_volume_price_models do |t|
4
6
  t.string :name
@@ -1,18 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SolidusVolumePricing
2
4
  module Generators
3
5
  class InstallGenerator < Rails::Generators::Base
4
6
  class_option :auto_run_migrations, type: :boolean, default: false
5
7
 
6
- def add_javascripts
7
- append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_volume_pricing\n"
8
- end
9
-
10
8
  def add_migrations
11
9
  run 'bundle exec rake railties:install:migrations FROM=solidus_volume_pricing'
12
10
  end
13
11
 
14
12
  def run_migrations
15
- run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
13
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(
14
+ ask('Would you like to run the migrations now? [Y/n]')
15
+ )
16
16
  if run_migrations
17
17
  run 'bundle exec rake db:migrate'
18
18
  else
@@ -1,42 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spree/core'
4
+
1
5
  module SolidusVolumePricing
2
6
  class Engine < Rails::Engine
3
- isolate_namespace Spree
7
+ include SolidusSupport::EngineExtensions
8
+
9
+ isolate_namespace ::Spree
10
+
4
11
  engine_name 'solidus_volume_pricing'
5
12
 
6
13
  initializer 'solidus_volume_pricing.preferences', before: 'spree.environment' do
7
- Spree::AppConfiguration.class_eval do
14
+ ::Spree::AppConfiguration.class_eval do
8
15
  preference :use_master_variant_volume_pricing, :boolean, default: false
9
- preference :volume_pricing_role, :string, default: 'wholesale'
10
16
  end
11
17
  end
12
18
 
13
19
  def self.activate
14
20
  Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
15
21
  Rails.configuration.cache_classes ? require(c) : load(c)
22
+ Rails.autoloaders.main.ignore(c) if Rails.autoloaders.zeitwerk_enabled?
16
23
  end
17
-
18
- String.class_eval do
19
- def to_range
20
- case count('.')
21
- when 2
22
- elements = split('..')
23
- return Range.new(elements[0].delete('(').to_i, elements[1].to_i)
24
- when 3
25
- elements = split('...')
26
- return Range.new(elements[0].delete('(').to_i, elements[1].to_i - 1)
27
- else
28
- raise ArgumentError.new(
29
- I18n.t(
30
- :'activerecord.errors.messages.could_not_conver_to_range',
31
- number: self
32
- )
33
- )
34
- end
35
- end
36
- end
24
+ ::Spree::BackendConfiguration::CONFIGURATION_TABS << :volume_price_models
37
25
  end
38
26
 
39
- config.autoload_paths += %W(#{config.root}/lib)
40
27
  config.to_prepare(&method(:activate).to_proc)
28
+
29
+ # use rspec for tests
30
+ config.generators do |g|
31
+ g.test_framework :rspec
32
+ end
41
33
  end
42
34
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusVolumePricing
4
+ class RangeFromString
5
+ attr_reader :range_string
6
+
7
+ RANGE_FORMAT = /\A\(?(\d+)(\.{2,3})(\d+)\)?\z/.freeze
8
+ OPEN_ENDED = /\(?[0-9]+\+\)?/.freeze
9
+
10
+ def initialize(range_string)
11
+ @range_string = range_string
12
+ end
13
+
14
+ def to_range
15
+ ::Range.new(*options_from_string)
16
+ end
17
+
18
+ private
19
+
20
+ def options_from_string
21
+ case range_string
22
+ when OPEN_ENDED
23
+ [range_string.tr("^0-9", '').to_i, Float::INFINITY]
24
+ when RANGE_FORMAT
25
+ [
26
+ Regexp.last_match[1].to_i,
27
+ Regexp.last_match[3].to_i,
28
+ Regexp.last_match[2].length == 3
29
+ ]
30
+ else
31
+ raise ArgumentError,
32
+ I18n.t(:could_not_convert_to_range, scope: 'activerecord.errors.messages', string: range_string)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :volume_price, class: 'Spree::VolumePrice' do
5
+ amount { 10 }
6
+ discount_type { 'price' }
7
+ range { '(1..5)' }
8
+ association :variant
9
+ end
10
+
11
+ factory :volume_price_model, class: 'Spree::VolumePriceModel' do
12
+ name { 'name' }
13
+ end
14
+ end
@@ -1,18 +1,5 @@
1
- module SolidusVolumePricing
2
- module_function
3
-
4
- # Returns the version of the currently loaded SolidusVolumePricing as a
5
- # <tt>Gem::Version</tt>.
6
- def version
7
- Gem::Version.new VERSION::STRING
8
- end
1
+ # frozen_string_literal: true
9
2
 
10
- module VERSION
11
- MAJOR = 0
12
- MINOR = 2
13
- TINY = 1
14
- PRE = nil
15
-
16
- STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
17
- end
3
+ module SolidusVolumePricing
4
+ VERSION = '1.1.0'
18
5
  end
@@ -1,6 +1,11 @@
1
- require 'sass/rails'
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/deprecation'
4
+ require 'sassc/rails'
2
5
  require 'deface'
3
6
  require 'solidus_core'
7
+ require 'solidus_support'
4
8
  require 'solidus_volume_pricing/engine'
5
9
  require 'solidus_volume_pricing/version'
10
+ require 'solidus_volume_pricing/range_from_string'
6
11
  require 'coffee_script'
@@ -1,40 +1,43 @@
1
- lib = File.expand_path('../lib/', __FILE__)
2
- $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
1
+ # frozen_string_literal: true
3
2
 
3
+ $:.push File.expand_path('lib', __dir__)
4
4
  require 'solidus_volume_pricing/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.name = 'solidus_volume_pricing'
9
- s.version = SolidusVolumePricing.version
9
+ s.version = SolidusVolumePricing::VERSION
10
10
  s.summary = 'Allow prices to be configured in quantity ranges for each variant'
11
11
  s.description = s.summary
12
- s.required_ruby_version = '>= 2.2.3'
12
+
13
+ s.required_ruby_version = '>= 2.5'
13
14
 
14
15
  s.author = 'Sean Schofield'
15
16
  s.email = 'sean@railsdog.com'
16
17
  s.homepage = 'https://github.com/solidusio-contrib/solidus_volume_pricing'
17
- s.license = 'BSD-3'
18
+ s.license = 'BSD-3-Clause'
19
+
20
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ s.test_files = Dir['spec/**/*']
24
+ s.bindir = "exe"
25
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
27
+
28
+ if s.respond_to?(:metadata)
29
+ s.metadata["homepage_uri"] = s.homepage if s.homepage
30
+ s.metadata["source_code_uri"] = s.homepage if s.homepage
31
+ end
18
32
 
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- spec/*`.split("\n")
21
- s.require_path = 'lib'
22
- s.requirements << 'none'
33
+ s.add_runtime_dependency 'solidus_backend', ['>= 2.4.0', '< 4']
23
34
 
24
- s.add_runtime_dependency 'solidus_core', '~> 1.3'
25
- s.add_runtime_dependency 'deface', '~> 1.0'
35
+ s.add_dependency 'coffee-rails'
36
+ s.add_dependency 'deface'
37
+ s.add_dependency 'sassc-rails'
38
+ s.add_dependency 'solidus_core', ['>= 2.4.0', '< 4']
39
+ s.add_dependency 'solidus_support', '~> 0.8'
26
40
 
27
- s.add_development_dependency 'sqlite3', '>= 1.3.10'
28
- s.add_development_dependency 'capybara', '~> 2.4'
29
- s.add_development_dependency 'ffaker', '>= 1.32.1'
30
41
  s.add_development_dependency 'shoulda-matchers'
31
- s.add_development_dependency 'rspec-rails', '~> 3.2'
32
- s.add_development_dependency 'simplecov', '~> 0.9'
33
- s.add_development_dependency 'factory_girl', '~> 4.5'
34
- s.add_development_dependency 'pry-rails', '>= 0.3'
35
- s.add_development_dependency 'poltergeist', '~> 1.6'
36
- s.add_development_dependency 'database_cleaner', '~> 1.4'
37
- s.add_development_dependency 'coffee-rails', '~> 4.0'
38
- s.add_development_dependency 'sass-rails', '~> 5.0'
39
- s.add_development_dependency 'rubocop', '>= 0.24.1'
42
+ s.add_development_dependency 'solidus_dev_support'
40
43
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Spree::Admin::VariantsController, type: :controller do
2
4
  stub_authorization!
3
5
 
@@ -6,21 +8,22 @@ RSpec.describe Spree::Admin::VariantsController, type: :controller do
6
8
  variant = create :variant
7
9
 
8
10
  expect do
9
- spree_put :update,
10
- product_id: variant.product.slug,
11
- id: variant.id,
12
- variant: {
13
- 'volume_prices_attributes' => {
14
- '1335830259720' => {
15
- 'name' => '5-10',
16
- 'discount_type' => 'price',
17
- 'range' => '5..10',
18
- 'amount' => '90',
19
- 'position' => '1',
20
- '_destroy' => 'false'
21
- }
22
- }
23
- }
11
+ put :update, params: {
12
+ product_id: variant.product.slug,
13
+ id: variant.id,
14
+ variant: {
15
+ 'volume_prices_attributes' => {
16
+ '1335830259720' => {
17
+ 'name' => '5-10',
18
+ 'discount_type' => 'price',
19
+ 'range' => '5..10',
20
+ 'amount' => '90',
21
+ 'position' => '1',
22
+ '_destroy' => 'false'
23
+ }
24
+ }
25
+ }
26
+ }
24
27
  end.to change(variant.volume_prices, :count).by(1)
25
28
  end
26
29
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- RSpec.feature 'Managing volume price models' do
5
+ RSpec.describe 'Managing volume price models' do
4
6
  stub_authorization!
5
7
 
6
- scenario 'a admin can create and remove volume price models', :js do
8
+ it 'an admin can create and remove volume price models', :js do
7
9
  visit spree.admin_volume_price_models_path
8
10
  expect(page).to have_content('Volume Price Models')
9
11
 
@@ -17,10 +19,6 @@ RSpec.feature 'Managing volume price models' do
17
19
  end
18
20
  click_on 'Create'
19
21
 
20
- within 'tr.volume_price.fields' do
21
- expect(page).to have_field('volume_price_model_volume_prices_attributes_0_name', with: '5 pieces discount')
22
- page.find('a[data-action="remove"]').click
23
- expect(page).to_not have_field('volume_price_model_volume_prices_attributes_0_name', with: '5 pieces discount')
24
- end
22
+ expect(page).to have_content('Discount')
25
23
  end
26
24
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- RSpec.feature 'Managing volume prices' do
5
+ RSpec.describe 'Managing volume prices' do
4
6
  stub_authorization!
5
7
 
6
8
  let(:variant) { create(:variant) }
7
9
 
8
- scenario 'a admin can create and remove volume prices', :js do
10
+ it 'an admin can create and remove volume prices', :js do
9
11
  visit spree.edit_admin_product_path(variant.product)
10
12
  click_on 'Volume Pricing'
11
13
  expect(page).to have_content('Volume Prices')
@@ -16,14 +18,13 @@ RSpec.feature 'Managing volume prices' do
16
18
  fill_in 'variant_volume_prices_attributes_0_amount', with: '1'
17
19
  click_on 'Update'
18
20
 
19
- within 'tr.volume_price.fields' do
20
- expect(page).to have_field('variant_volume_prices_attributes_0_name', with: '5 pieces discount')
21
- page.find('a[data-action="remove"]').click
22
- expect(page).to_not have_field('variant_volume_prices_attributes_0_name', with: '5 pieces discount')
23
- end
21
+ expect(page).to have_field('variant_volume_prices_attributes_0_name', with: '5 pieces discount')
22
+ accept_confirm { page.find('a[data-action="remove"]').click }
23
+
24
+ expect(page).not_to have_field('variant_volume_prices_attributes_0_name', with: '5 pieces discount')
24
25
  end
25
26
 
26
- scenario 'a admin editing a variant has a new volume price already built for her' do
27
+ it 'an admin editing a variant has a new volume price already built for her' do
27
28
  visit spree.edit_admin_product_variant_path(product_id: variant.product, id: variant)
28
29
  within '#volume_prices' do
29
30
  expect(page).to have_field('variant_volume_prices_attributes_0_name')
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Spree::BaseHelper, type: :helper do
2
- include Spree::BaseHelper
4
+ include described_class
3
5
 
4
6
  context 'volume pricing' do
5
7
  before do