solidus_volume_pricing 1.0.0 → 1.1.1
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 +4 -4
- data/.circleci/config.yml +50 -12
- data/.gem_release.yml +5 -0
- data/.github/dependabot.yml +7 -0
- data/.github/stale.yml +1 -0
- data/.github_changelog_generator +2 -0
- data/.gitignore +15 -7
- data/.rspec +1 -2
- data/.rubocop.yml +2 -7
- data/.rubocop_todo.yml +18 -76
- data/CHANGELOG.md +1 -55
- data/Gemfile +26 -12
- data/{LICENSE.md → LICENSE} +2 -2
- data/OLD_CHANGELOG.md +86 -0
- data/README.md +5 -5
- data/Rakefile +4 -19
- data/app/controllers/spree/admin/volume_price_models_controller.rb +1 -1
- data/app/decorators/models/solidus_volume_pricing/spree/variant_decorator.rb +6 -4
- data/app/models/spree/volume_price.rb +41 -41
- data/app/models/spree/volume_price_model.rb +9 -7
- data/app/views/spree/admin/volume_prices/_volume_price_fields.html.erb +5 -3
- data/bin/console +17 -0
- data/bin/rails +5 -6
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/rake +7 -0
- data/bin/sandbox +78 -0
- data/bin/setup +8 -0
- data/db/migrate/20150603143015_create_spree_volume_price_models.rb +1 -0
- data/lib/generators/solidus_volume_pricing/install/install_generator.rb +8 -4
- data/lib/solidus_volume_pricing/engine.rb +13 -3
- data/{spec/factories/volume_price_factory.rb → lib/solidus_volume_pricing/testing_support/factories.rb} +2 -2
- data/lib/solidus_volume_pricing/version.rb +1 -16
- data/lib/solidus_volume_pricing.rb +1 -0
- data/solidus_volume_pricing.gemspec +38 -29
- data/spec/controllers/spree/admin/variants_controller_spec.rb +1 -1
- data/spec/features/manage_volume_price_models_feature_spec.rb +3 -7
- data/spec/features/manage_volume_prices_feature_spec.rb +6 -7
- data/spec/lib/solidus_volume_pricing/range_from_string_spec.rb +2 -2
- data/spec/models/solidus_volume_pricing/pricer_spec.rb +0 -4
- data/spec/models/spree/line_item_spec.rb +0 -1
- data/spec/models/spree/volume_price_spec.rb +1 -10
- data/spec/spec_helper.rb +26 -5
- metadata +98 -30
- data/app/decorators/models/solidus_volume_pricing/spree/user_decorator.rb +0 -17
@@ -1,52 +1,52 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
roles <<
|
3
|
+
module Spree
|
4
|
+
class VolumePrice < ApplicationRecord
|
5
|
+
belongs_to :variant, touch: true, optional: true
|
6
|
+
belongs_to :volume_price_model, touch: true, optional: true
|
7
|
+
belongs_to :spree_role, class_name: 'Spree::Role', foreign_key: 'role_id', optional: true
|
8
|
+
acts_as_list scope: [:variant_id, :volume_price_model_id]
|
9
|
+
|
10
|
+
validates :amount, presence: true
|
11
|
+
validates :discount_type,
|
12
|
+
presence: true,
|
13
|
+
inclusion: {
|
14
|
+
in: %w(price dollar percent)
|
15
|
+
}
|
16
|
+
|
17
|
+
validate :range_format
|
18
|
+
|
19
|
+
def self.for_variant(variant, user: nil)
|
20
|
+
roles = [nil]
|
21
|
+
user&.spree_roles&.each { |r| roles << r.id }
|
22
|
+
|
23
|
+
where(
|
24
|
+
arel_table[:variant_id].eq(variant.id).
|
25
|
+
or(
|
26
|
+
arel_table[:volume_price_model_id].in(variant.volume_price_model_ids)
|
27
|
+
)
|
28
|
+
).
|
29
|
+
where(role_id: roles).
|
30
|
+
order(position: :asc, amount: :asc)
|
22
31
|
end
|
23
32
|
|
24
|
-
|
25
|
-
arel_table[:variant_id].eq(variant.id).
|
26
|
-
or(
|
27
|
-
arel_table[:volume_price_model_id].in(variant.volume_price_model_ids)
|
28
|
-
)
|
29
|
-
).
|
30
|
-
where(role_id: roles).
|
31
|
-
order(position: :asc, amount: :asc)
|
32
|
-
end
|
33
|
-
|
34
|
-
delegate :include?, to: :range_from_string
|
33
|
+
delegate :include?, to: :range_from_string
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def display_range
|
36
|
+
range.gsub(/\.+/, "-").gsub(/\(|\)/, '')
|
37
|
+
end
|
39
38
|
|
40
|
-
|
39
|
+
private
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
def range_format
|
42
|
+
if !(SolidusVolumePricing::RangeFromString::RANGE_FORMAT =~ range ||
|
43
|
+
SolidusVolumePricing::RangeFromString::OPEN_ENDED =~ range)
|
44
|
+
errors.add(:range, :must_be_in_format)
|
45
|
+
end
|
46
46
|
end
|
47
|
-
end
|
48
47
|
|
49
|
-
|
50
|
-
|
48
|
+
def range_from_string
|
49
|
+
SolidusVolumePricing::RangeFromString.new(range).to_range
|
50
|
+
end
|
51
51
|
end
|
52
52
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
module Spree
|
4
|
+
class VolumePriceModel < ApplicationRecord
|
5
|
+
has_many :variants, dependent: :nullify
|
6
|
+
has_many :volume_prices, -> { order(position: :asc) }, dependent: :destroy
|
7
|
+
accepts_nested_attributes_for :volume_prices, allow_destroy: true,
|
8
|
+
reject_if: proc { |volume_price|
|
9
|
+
volume_price[:amount].blank? && volume_price[:range].blank?
|
10
|
+
}
|
11
|
+
end
|
10
12
|
end
|
@@ -27,7 +27,9 @@
|
|
27
27
|
<%= error_message_on(f.object, :role_id) %>
|
28
28
|
<%= f.collection_select(:role_id, Spree::Role.all, :id, :name, { include_blank: t('spree.match_choices.none') }, { class: 'custom-select' }) %>
|
29
29
|
</td>
|
30
|
-
|
31
|
-
|
32
|
-
|
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>
|
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,8 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
if %w[g generate].include? ARGV.first
|
4
|
+
exec "#{__dir__}/rails-engine", *ARGV
|
5
|
+
else
|
6
|
+
exec "#{__dir__}/rails-sandbox", *ARGV
|
7
|
+
end
|
data/bin/rails-engine
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/solidus_volume_pricing/engine', __dir__)
|
7
|
+
|
8
|
+
# Set up gems listed in the Gemfile.
|
9
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
10
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
11
|
+
|
12
|
+
require 'rails/all'
|
13
|
+
require 'rails/engine/commands'
|
data/bin/rails-sandbox
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
app_root = 'sandbox'
|
4
|
+
|
5
|
+
unless File.exist? "#{app_root}/bin/rails"
|
6
|
+
warn 'Creating the sandbox app...'
|
7
|
+
Dir.chdir "#{__dir__}/.." do
|
8
|
+
system "#{__dir__}/sandbox" or begin
|
9
|
+
warn 'Automatic creation of the sandbox app failed'
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir.chdir app_root
|
16
|
+
exec 'bin/rails', *ARGV
|
data/bin/rake
ADDED
data/bin/sandbox
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
test -z "${DEBUG+empty_string}" || set -x
|
5
|
+
|
6
|
+
test "$DB" = "sqlite" && export DB="sqlite3"
|
7
|
+
|
8
|
+
if [ -z "$SOLIDUS_BRANCH" ]
|
9
|
+
then
|
10
|
+
echo "~~> Use 'export SOLIDUS_BRANCH=[master|v3.2|...]' to control the Solidus branch"
|
11
|
+
SOLIDUS_BRANCH="master"
|
12
|
+
fi
|
13
|
+
echo "~~> Using branch $SOLIDUS_BRANCH of solidus"
|
14
|
+
|
15
|
+
if [ -z "$SOLIDUS_FRONTEND" ]
|
16
|
+
then
|
17
|
+
echo "~~> Use 'export SOLIDUS_FRONTEND=[solidus_frontend|solidus_starter_frontend]' to control the Solidus frontend"
|
18
|
+
SOLIDUS_FRONTEND="solidus_frontend"
|
19
|
+
fi
|
20
|
+
echo "~~> Using branch $SOLIDUS_FRONTEND as the solidus frontend"
|
21
|
+
|
22
|
+
extension_name="solidus_volume_pricing"
|
23
|
+
|
24
|
+
# Stay away from the bundler env of the containing extension.
|
25
|
+
function unbundled {
|
26
|
+
ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
|
27
|
+
}
|
28
|
+
|
29
|
+
rm -rf ./sandbox
|
30
|
+
unbundled bundle exec rails new sandbox \
|
31
|
+
--database="${DB:-sqlite3}" \
|
32
|
+
--skip-bundle \
|
33
|
+
--skip-git \
|
34
|
+
--skip-keeps \
|
35
|
+
--skip-rc \
|
36
|
+
--skip-spring \
|
37
|
+
--skip-test \
|
38
|
+
--skip-javascript
|
39
|
+
|
40
|
+
if [ ! -d "sandbox" ]; then
|
41
|
+
echo 'sandbox rails application failed'
|
42
|
+
exit 1
|
43
|
+
fi
|
44
|
+
|
45
|
+
cd ./sandbox
|
46
|
+
cat <<RUBY >> Gemfile
|
47
|
+
gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH'
|
48
|
+
gem 'rails-i18n'
|
49
|
+
gem 'solidus_i18n'
|
50
|
+
|
51
|
+
gem '$extension_name', path: '..'
|
52
|
+
|
53
|
+
group :test, :development do
|
54
|
+
platforms :mri do
|
55
|
+
gem 'pry-byebug'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
RUBY
|
59
|
+
|
60
|
+
unbundled bundle install --gemfile Gemfile
|
61
|
+
|
62
|
+
unbundled bundle exec rake db:drop db:create
|
63
|
+
|
64
|
+
unbundled bundle exec rails generate solidus:install \
|
65
|
+
--auto-accept \
|
66
|
+
--user_class=Spree::User \
|
67
|
+
--enforce_available_locales=true \
|
68
|
+
--with-authentication=true \
|
69
|
+
--payment-method=none \
|
70
|
+
--frontend=${SOLIDUS_FRONTEND} \
|
71
|
+
$@
|
72
|
+
|
73
|
+
unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations
|
74
|
+
unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations
|
75
|
+
|
76
|
+
echo
|
77
|
+
echo "🚀 Sandbox app successfully created for $extension_name!"
|
78
|
+
echo "🧪 This app is intended for test purposes."
|
data/bin/setup
ADDED
@@ -10,6 +10,7 @@ class CreateSpreeVolumePriceModels < ActiveRecord::Migration[4.2]
|
|
10
10
|
create_table :spree_variants_volume_price_models do |t|
|
11
11
|
t.belongs_to :volume_price_model
|
12
12
|
t.belongs_to :variant
|
13
|
+
t.timestamps
|
13
14
|
end
|
14
15
|
|
15
16
|
add_reference :spree_volume_prices, :volume_price_model
|
@@ -5,16 +5,20 @@ module SolidusVolumePricing
|
|
5
5
|
class InstallGenerator < Rails::Generators::Base
|
6
6
|
class_option :auto_run_migrations, type: :boolean, default: false
|
7
7
|
|
8
|
+
def self.exit_on_failure?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
8
12
|
def add_migrations
|
9
|
-
run '
|
13
|
+
run 'bin/rails railties:install:migrations FROM=solidus_volume_pricing'
|
10
14
|
end
|
11
15
|
|
12
16
|
def run_migrations
|
13
|
-
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
17
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
|
14
18
|
if run_migrations
|
15
|
-
run '
|
19
|
+
run 'bin/rails db:migrate'
|
16
20
|
else
|
17
|
-
puts 'Skipping
|
21
|
+
puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
@@ -1,25 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'spree/core'
|
4
|
+
require 'solidus_support'
|
5
|
+
|
3
6
|
module SolidusVolumePricing
|
4
7
|
class Engine < Rails::Engine
|
8
|
+
include SolidusSupport::EngineExtensions
|
9
|
+
|
5
10
|
isolate_namespace ::Spree
|
11
|
+
|
6
12
|
engine_name 'solidus_volume_pricing'
|
7
13
|
|
8
14
|
initializer 'solidus_volume_pricing.preferences', before: 'spree.environment' do
|
9
15
|
::Spree::AppConfiguration.class_eval do
|
10
16
|
preference :use_master_variant_volume_pricing, :boolean, default: false
|
11
|
-
preference :volume_pricing_role, :string, default: 'wholesale'
|
12
17
|
end
|
13
18
|
end
|
14
19
|
|
15
20
|
def self.activate
|
16
|
-
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
21
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')).sort.each do |c|
|
17
22
|
Rails.configuration.cache_classes ? require(c) : load(c)
|
23
|
+
Rails.autoloaders.main.ignore(c) if Rails.autoloaders.zeitwerk_enabled?
|
18
24
|
end
|
19
25
|
::Spree::BackendConfiguration::CONFIGURATION_TABS << :volume_price_models
|
20
26
|
end
|
21
27
|
|
22
|
-
config.autoload_paths += %W(#{config.root}/lib)
|
23
28
|
config.to_prepare(&method(:activate).to_proc)
|
29
|
+
|
30
|
+
# use rspec for tests
|
31
|
+
config.generators do |g|
|
32
|
+
g.test_framework :rspec
|
33
|
+
end
|
24
34
|
end
|
25
35
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
FactoryBot.define do
|
4
|
-
factory :volume_price, class: Spree::VolumePrice do
|
4
|
+
factory :volume_price, class: 'Spree::VolumePrice' do
|
5
5
|
amount { 10 }
|
6
6
|
discount_type { 'price' }
|
7
7
|
range { '(1..5)' }
|
8
8
|
association :variant
|
9
9
|
end
|
10
10
|
|
11
|
-
factory :volume_price_model, class: Spree::VolumePriceModel do
|
11
|
+
factory :volume_price_model, class: 'Spree::VolumePriceModel' do
|
12
12
|
name { 'name' }
|
13
13
|
end
|
14
14
|
end
|
@@ -1,20 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SolidusVolumePricing
|
4
|
-
|
5
|
-
|
6
|
-
# Returns the version of the currently loaded SolidusVolumePricing as a
|
7
|
-
# <tt>Gem::Version</tt>.
|
8
|
-
def version
|
9
|
-
Gem::Version.new VERSION::STRING
|
10
|
-
end
|
11
|
-
|
12
|
-
module VERSION
|
13
|
-
MAJOR = 1
|
14
|
-
MINOR = 0
|
15
|
-
TINY = 0
|
16
|
-
PRE = nil
|
17
|
-
|
18
|
-
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
|
19
|
-
end
|
4
|
+
VERSION = '1.1.1'
|
20
5
|
end
|
@@ -4,6 +4,7 @@ require 'active_support/deprecation'
|
|
4
4
|
require 'sassc/rails'
|
5
5
|
require 'deface'
|
6
6
|
require 'solidus_core'
|
7
|
+
require 'solidus_support'
|
7
8
|
require 'solidus_volume_pricing/engine'
|
8
9
|
require 'solidus_volume_pricing/version'
|
9
10
|
require 'solidus_volume_pricing/range_from_string'
|
@@ -1,32 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
3
|
+
require_relative 'lib/solidus_volume_pricing/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'solidus_volume_pricing'
|
7
|
+
spec.version = SolidusVolumePricing::VERSION
|
8
|
+
spec.authors = ['Sean Schofield']
|
9
|
+
spec.email = 'sean@railsdog.com'
|
10
|
+
|
11
|
+
spec.summary = 'Allow prices to be configured in quantity ranges for each variant'
|
12
|
+
spec.description = 'Allow prices to be configured in quantity ranges for each variant'
|
13
|
+
spec.homepage = 'https://github.com/solidusio-contrib/solidus_volume_pricing'
|
14
|
+
spec.license = 'BSD-3-Clause'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_volume_pricing'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_volume_pricing/releases'
|
19
|
+
|
20
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 4')
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
|
25
|
+
|
26
|
+
spec.files = files.grep_v(%r{^(test|spec|features)/})
|
27
|
+
spec.test_files = files.grep(%r{^(test|spec|features)/})
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_runtime_dependency 'solidus_backend', ['>= 2.4.0', '< 5']
|
33
|
+
spec.add_dependency 'coffee-rails'
|
34
|
+
spec.add_dependency 'deface'
|
35
|
+
spec.add_dependency 'sassc-rails'
|
36
|
+
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 5']
|
37
|
+
spec.add_dependency 'solidus_support', '~> 0.8'
|
38
|
+
|
39
|
+
spec.add_development_dependency 'shoulda-matchers'
|
40
|
+
spec.add_development_dependency 'solidus_dev_support', '~> 2.6'
|
32
41
|
end
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
RSpec.describe 'Managing volume price models' do
|
5
|
+
RSpec.describe 'Managing volume price models', type: :system do
|
6
6
|
stub_authorization!
|
7
7
|
|
8
|
-
it '
|
8
|
+
it 'an admin can create and remove volume price models', :js do
|
9
9
|
visit spree.admin_volume_price_models_path
|
10
10
|
expect(page).to have_content('Volume Price Models')
|
11
11
|
|
@@ -19,10 +19,6 @@ RSpec.describe 'Managing volume price models' do
|
|
19
19
|
end
|
20
20
|
click_on 'Create'
|
21
21
|
|
22
|
-
|
23
|
-
expect(page).to have_field('volume_price_model_volume_prices_attributes_0_name', with: '5 pieces discount')
|
24
|
-
page.find('a[data-action="remove"]').click
|
25
|
-
expect(page).not_to have_field('volume_price_model_volume_prices_attributes_0_name', with: '5 pieces discount')
|
26
|
-
end
|
22
|
+
expect(page).to have_content('Discount')
|
27
23
|
end
|
28
24
|
end
|
@@ -7,7 +7,7 @@ RSpec.describe 'Managing volume prices' do
|
|
7
7
|
|
8
8
|
let(:variant) { create(:variant) }
|
9
9
|
|
10
|
-
it '
|
10
|
+
it 'an admin can create and remove volume prices', :js do
|
11
11
|
visit spree.edit_admin_product_path(variant.product)
|
12
12
|
click_on 'Volume Pricing'
|
13
13
|
expect(page).to have_content('Volume Prices')
|
@@ -18,14 +18,13 @@ RSpec.describe 'Managing volume prices' do
|
|
18
18
|
fill_in 'variant_volume_prices_attributes_0_amount', with: '1'
|
19
19
|
click_on 'Update'
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
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')
|
26
25
|
end
|
27
26
|
|
28
|
-
it '
|
27
|
+
it 'an admin editing a variant has a new volume price already built for her' do
|
29
28
|
visit spree.edit_admin_product_variant_path(product_id: variant.product, id: variant)
|
30
29
|
within '#volume_prices' do
|
31
30
|
expect(page).to have_field('variant_volume_prices_attributes_0_name')
|
@@ -30,13 +30,13 @@ RSpec.describe SolidusVolumePricing::RangeFromString do
|
|
30
30
|
it { is_expected.to eq(1...2) }
|
31
31
|
end
|
32
32
|
|
33
|
-
context 'with an open-ended string like
|
33
|
+
context 'with an open-ended string like x+' do
|
34
34
|
let(:argument) { '10+' }
|
35
35
|
|
36
36
|
it { is_expected.to eq(10..Float::INFINITY) }
|
37
37
|
end
|
38
38
|
|
39
|
-
context 'with an open-ended string like
|
39
|
+
context 'with an open-ended string like x+" and parens' do
|
40
40
|
let(:argument) { '(10+)' }
|
41
41
|
|
42
42
|
it { is_expected.to eq(10..Float::INFINITY) }
|
@@ -14,10 +14,6 @@ RSpec.describe SolidusVolumePricing::Pricer do
|
|
14
14
|
let(:user) { create(:user) }
|
15
15
|
let(:variant) { create(:variant, price: 10) }
|
16
16
|
|
17
|
-
before do
|
18
|
-
stub_spree_preferences(volume_pricing_role: role.name)
|
19
|
-
end
|
20
|
-
|
21
17
|
it 'inherits from default variant pricer' do
|
22
18
|
expect(described_class < Spree::Variant::PriceSelector).to be(true)
|
23
19
|
end
|
@@ -19,7 +19,6 @@ RSpec.describe Spree::LineItem, type: :model do
|
|
19
19
|
|
20
20
|
it 'updates the line item price when the quantity changes to match a range and role matches' do
|
21
21
|
order.user.spree_roles << role
|
22
|
-
stub_spree_preferences(volume_pricing_role: role.name)
|
23
22
|
expect(order.user.has_spree_role?(role.name.to_sym)).to be(true)
|
24
23
|
variant.volume_prices.first.update(role_id: role.id)
|
25
24
|
expect(line_item.price.to_f).to be(10.00)
|
@@ -11,12 +11,7 @@ RSpec.describe Spree::VolumePrice, type: :model do
|
|
11
11
|
it { is_expected.to validate_presence_of(:discount_type) }
|
12
12
|
it { is_expected.to validate_presence_of(:amount) }
|
13
13
|
|
14
|
-
it
|
15
|
-
expect(subject).to \
|
16
|
-
validate_inclusion_of(:discount_type).
|
17
|
-
in_array(%w(price dollar percent)).
|
18
|
-
with_message('shoulda-matchers test string is not a valid Volume Price Type')
|
19
|
-
end
|
14
|
+
it { is_expected.to validate_inclusion_of(:discount_type).in_array(%w[price dollar percent]) }
|
20
15
|
|
21
16
|
describe '.for_variant' do
|
22
17
|
subject { described_class.for_variant(variant, user: user) }
|
@@ -44,10 +39,6 @@ RSpec.describe Spree::VolumePrice, type: :model do
|
|
44
39
|
create_list(:volume_price, 2, variant: variant, role_id: role.id)
|
45
40
|
end
|
46
41
|
|
47
|
-
before do
|
48
|
-
stub_spree_preferences(volume_pricing_role: role.name)
|
49
|
-
end
|
50
|
-
|
51
42
|
context 'whose role matches' do
|
52
43
|
before do
|
53
44
|
user.spree_roles = [role]
|