spree_sale_prices 1.0.0 → 2.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. metadata +4 -50
  3. data/.gitignore +0 -14
  4. data/.rspec +0 -1
  5. data/Gemfile +0 -5
  6. data/LICENSE +0 -26
  7. data/README.md +0 -158
  8. data/Rakefile +0 -21
  9. data/Versionfile +0 -10
  10. data/app/assets/javascripts/spree/backend/spree_sale_prices.js +0 -0
  11. data/app/assets/javascripts/spree/frontend/spree_sale_prices.js +0 -0
  12. data/app/assets/stylesheets/spree/backend/spree_sale_prices.css +0 -0
  13. data/app/assets/stylesheets/spree/frontend/spree_sale_prices.css +0 -0
  14. data/app/controllers/spree/admin/sale_prices_controller.rb +0 -43
  15. data/app/helpers/spree/base_helper_decorator.rb +0 -30
  16. data/app/models/spree/calculator/dollar_amount_sale_price_calculator.rb +0 -14
  17. data/app/models/spree/calculator/fixed_amount_sale_price_calculator.rb +0 -12
  18. data/app/models/spree/calculator/percent_off_sale_price_calculator.rb +0 -12
  19. data/app/models/spree/price_decorator.rb +0 -97
  20. data/app/models/spree/product_decorator.rb +0 -50
  21. data/app/models/spree/sale_price.rb +0 -63
  22. data/app/models/spree/variant_decorator.rb +0 -71
  23. data/app/overrides/admin_product_tabs.rb +0 -6
  24. data/app/views/spree/admin/sale_prices/_sale_price.html.slim +0 -8
  25. data/app/views/spree/admin/sale_prices/_table.html.slim +0 -18
  26. data/app/views/spree/admin/sale_prices/create.js.erb +0 -1
  27. data/app/views/spree/admin/sale_prices/destroy.js.erb +0 -1
  28. data/app/views/spree/admin/sale_prices/index.html.slim +0 -36
  29. data/config/locales/de.yml +0 -14
  30. data/config/locales/en.yml +0 -14
  31. data/config/routes.rb +0 -7
  32. data/db/migrate/20120403135246_create_sale_prices.rb +0 -19
  33. data/db/migrate/20140309000000_change_data_type_for_value.rb +0 -5
  34. data/lib/generators/spree_sale_prices/install/install_generator.rb +0 -19
  35. data/lib/spree_sale_prices.rb +0 -2
  36. data/lib/spree_sale_prices/engine.rb +0 -20
  37. data/lib/spree_sale_prices/factories.rb +0 -35
  38. data/spec/models/price_spec.rb +0 -58
  39. data/spec/models/product_spec.rb +0 -18
  40. data/spec/models/sale_price_spec.rb +0 -38
  41. data/spec/models/variant_spec.rb +0 -150
  42. data/spec/spec_helper.rb +0 -87
  43. data/spree_sale_prices.gemspec +0 -28
@@ -1,19 +0,0 @@
1
- module SpreeSalePrices
2
- module Generators
3
- class InstallGenerator < Rails::Generators::Base
4
-
5
- def add_migrations
6
- run 'bundle exec rake railties:install:migrations FROM=spree_sale_prices'
7
- end
8
-
9
- def run_migrations
10
- res = ask "Would you like to run the migrations now? [Y/n]"
11
- if res == "" || res.downcase == "y"
12
- run 'bundle exec rake db:migrate'
13
- else
14
- puts "Skiping rake db:migrate, don't forget to run it!"
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,2 +0,0 @@
1
- require 'spree_core'
2
- require 'spree_sale_prices/engine'
@@ -1,20 +0,0 @@
1
- module SpreeSalePrices
2
- class Engine < Rails::Engine
3
- engine_name 'spree_sale_prices'
4
-
5
- config.autoload_paths += %W(#{config.root}/lib)
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
@@ -1,35 +0,0 @@
1
- FactoryGirl.define do
2
- # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
3
- #
4
- # Example adding this to your spec_helper will load these Factories for use:
5
- # require 'spree_sale_prices/factories'
6
-
7
- factory :sale_price, class: Spree::SalePrice do
8
- value 10.90
9
- start_at nil
10
- end_at nil
11
- enabled false
12
- calculator { Spree::Calculator::FixedAmountSalePriceCalculator.new }
13
- association :price, factory: :international_price
14
-
15
- factory :active_sale_price do
16
- start_at { Time.now }
17
- enabled true
18
- end
19
- end
20
-
21
- factory :international_price, parent: :price do
22
- currency { Faker::Currency.code }
23
- end
24
-
25
- factory :multi_price_variant, parent: :variant do
26
- transient do
27
- prices_count 3
28
- end
29
-
30
- after(:create) do |variant, evaluator|
31
- create_list(:international_price, evaluator.prices_count, variant: variant)
32
- end
33
- end
34
-
35
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Price do
4
-
5
- it 'can build a new sale by factory' do
6
- price = build(:price)
7
- sale_price = price.new_sale(15.99)
8
-
9
- expect(price.on_sale?).to be false
10
- expect(price.price).to eql BigDecimal.new(19.99, 4)
11
-
12
- expect(sale_price).to have_attributes({
13
- value: BigDecimal.new(15.99, 4),
14
- start_at: be_within(1.second).of(Time.now),
15
- end_at: nil,
16
- enabled: true,
17
- calculator: an_instance_of(Spree::Calculator::FixedAmountSalePriceCalculator)
18
- })
19
- end
20
-
21
- it 'can put a price on a fixed sale' do
22
- price = create(:price)
23
- price.put_on_sale 15.95
24
-
25
- expect(price.on_sale?).to be true
26
- expect(price.price).to eql BigDecimal.new(15.95, 4)
27
- expect(price.original_price).to eql(19.99)
28
- end
29
-
30
- it 'can put a price on a percent-off sale' do
31
- price = create(:price)
32
- price.put_on_sale 0.2, { calculator_type: Spree::Calculator::PercentOffSalePriceCalculator.new }
33
-
34
- expect(price.on_sale?).to be true
35
- expect(price.price).to be_within(0.01).of(15.99)
36
- expect(price.original_price).to eql(19.99)
37
- end
38
-
39
- context 'calculating discount percentage' do
40
- it 'returns 0 if there\'s no original price' do
41
- price = create(:price)
42
- price.amount = BigDecimal(0)
43
- expect(price.discount_percent.to_f).to eql 0.0
44
- end
45
-
46
- it 'returns 0 if it\'s not on sale' do
47
- price = create(:price)
48
- expect(price.discount_percent.to_f).to eql 0.0
49
- end
50
-
51
- it 'returns correct percentage value' do
52
- price = create(:price)
53
- price.put_on_sale(15.00)
54
- expect(price.discount_percent.to_f).to be_within(0.1).of(25)
55
- end
56
- end
57
-
58
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Product do
4
-
5
- it 'can put a product on sale' do
6
- product = create(:product)
7
- expect(product.price).to eql 19.99
8
- expect(product.original_price).to eql 19.99
9
- expect(product.on_sale?).to be false
10
-
11
- product.put_on_sale 10.95
12
-
13
- expect(product.price).to eql 10.95
14
- expect(product.original_price).to eql 19.99
15
- expect(product.on_sale?).to be true
16
- end
17
-
18
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::SalePrice do
4
-
5
- it 'can start and end never' do
6
- sale_price = build(:sale_price)
7
- sale_price.start
8
-
9
- expect(sale_price).to be_enabled
10
- expect(sale_price.end_at).to be(nil)
11
- end
12
-
13
- it 'can start and then end at a specific time' do
14
- sale_price = build(:sale_price)
15
- sale_price.start(1.day.from_now)
16
-
17
- expect(sale_price).to be_enabled
18
- expect(sale_price.end_at).to be_within(1.second).of(1.day.from_now)
19
- end
20
-
21
- it 'can stop' do
22
- sale_price = build(:active_sale_price)
23
- sale_price.stop
24
-
25
- expect(sale_price).not_to be_enabled
26
- expect(sale_price.end_at).to be_within(1.second).of(Time.now)
27
- end
28
-
29
- it 'can create a money price ready to display' do
30
- sale_price = build(:active_sale_price)
31
- money = sale_price.display_price
32
-
33
- expect(money).to be_a Spree::Money
34
- expect(money.money.amount).to eq(sale_price.calculated_price)
35
- expect(money.money.currency).to eq(sale_price.currency)
36
- end
37
-
38
- end
@@ -1,150 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Variant do
4
-
5
- it 'can put a variant on a standard sale' do
6
- variant = create(:variant)
7
- expect(variant.on_sale?).to be false
8
-
9
- variant.put_on_sale 10.95
10
-
11
- expect(variant.on_sale?).to be true
12
- expect(variant.original_price).to eql 19.99
13
- expect(variant.price).to eql 10.95
14
- end
15
-
16
- it 'changes the price of all attached prices' do
17
- variant = create(:multi_price_variant)
18
- variant.put_on_sale 10.95
19
-
20
- expect(variant.prices.count).not_to eql 0
21
- variant.prices.each do |p|
22
- expect(p.price).to eql BigDecimal.new(10.95, 4)
23
- end
24
- end
25
-
26
- it 'changes the price for each specific currency' do
27
- variant = create(:multi_price_variant, prices_count: 5)
28
-
29
- variant.prices.each do |p|
30
- variant.put_on_sale 10.95, { currencies: [ p.currency ] }
31
-
32
- expect(variant.price_in(p.currency).price).to eq BigDecimal.new(10.95, 4)
33
- expect(variant.original_price_in(p.currency).price).to eql BigDecimal.new(19.99, 4)
34
- end
35
- end
36
-
37
- it 'changes the price for multiple currencies' do
38
- variant = create(:multi_price_variant, prices_count: 5)
39
- some_prices = variant.prices.sample(3)
40
-
41
- variant.put_on_sale(10.95, {
42
- currencies: some_prices.map(&:currency)
43
- # TODO: does not work yet, because sale_prices take the calculator instance away from each other
44
- #calculator_type: Spree::Calculator::PercentOffSalePriceCalculator.new
45
- })
46
-
47
- some_prices.each do |p|
48
- expect(variant.price_in(p.currency).price).to be_within(0.01).of(10.95)
49
- expect(variant.original_price_in(p.currency).price).to eql BigDecimal.new(19.99, 4)
50
- end
51
- end
52
-
53
- it 'can set the original price to something different without changing the sale price' do
54
- variant = create(:multi_price_variant, prices_count: 5)
55
- variant.put_on_sale(10.95)
56
- variant.prices.each do |p|
57
- p.original_price = 12.90
58
- end
59
-
60
- variant.prices.each do |p|
61
- expect(p.on_sale?).to be true
62
- expect(p.price).to eq BigDecimal.new(10.95, 4)
63
- expect(p.sale_price).to eq BigDecimal.new(10.95, 4)
64
- expect(p.original_price).to eq BigDecimal.new(12.90, 4)
65
- end
66
- end
67
-
68
- it 'is not on sale anymore if the original price is lower than the sale price' do
69
- variant = create(:multi_price_variant, prices_count: 5)
70
- variant.put_on_sale(10.95)
71
- variant.prices.each do |p|
72
- p.original_price = 9.90
73
- end
74
-
75
- variant.prices.each do |p|
76
- expect(p.on_sale?).to be false
77
- expect(p.price).to eq BigDecimal.new(9.90, 4)
78
- expect(p.sale_price).to eq nil
79
- expect(p.original_price).to eq BigDecimal.new(9.90, 4)
80
- end
81
- end
82
-
83
- context 'with a valid sale' do
84
-
85
- before(:each) do
86
- @variant = create(:multi_price_variant, prices_count: 5)
87
- @variant.put_on_sale(10.95) # sale is started and enabled at this point for all currencies
88
- end
89
-
90
- it 'can stop and start a sale for all currencies' do
91
- @variant.stop_sale
92
- @variant.prices.each do |p|
93
- expect(@variant.on_sale_in?(p.currency)).to be false
94
- end
95
-
96
- @variant.start_sale
97
- @variant.prices.each do |p|
98
- expect(@variant.on_sale_in?(p.currency)).to be true
99
- end
100
- end
101
-
102
- it 'can disable and enable a sale for all currencies' do
103
- @variant.disable_sale
104
- @variant.prices.each do |p|
105
- expect(@variant.on_sale_in?(p.currency)).to be false
106
- end
107
-
108
- @variant.enable_sale
109
- @variant.prices.each do |p|
110
- expect(@variant.on_sale_in?(p.currency)).to be true
111
- end
112
- end
113
-
114
- it 'can stop and start a sale for specific currencies' do
115
- price_groups = @variant.prices.in_groups(2)
116
- @variant.stop_sale(price_groups.first.map(&:currency))
117
-
118
- price_groups.first.each do |p|
119
- expect(@variant.on_sale_in?(p.currency)).to be false
120
- end
121
- price_groups.second.each do |p|
122
- expect(@variant.on_sale_in?(p.currency)).to be true
123
- end
124
-
125
- @variant.start_sale(1.second.ago, price_groups.first.map(&:currency))
126
- @variant.prices.each do |p|
127
- expect(@variant.on_sale_in?(p.currency)).to be true
128
- end
129
- end
130
-
131
- it 'can disable and enable a sale for specific currencies' do
132
- price_groups = @variant.prices.in_groups(2)
133
- @variant.disable_sale(price_groups.first.map(&:currency))
134
-
135
- price_groups.first.each do |p|
136
- expect(@variant.on_sale_in?(p.currency)).to be false
137
- end
138
- price_groups.second.each do |p|
139
- expect(@variant.on_sale_in?(p.currency)).to be true
140
- end
141
-
142
- @variant.enable_sale(price_groups.first.map(&:currency))
143
- @variant.prices.each do |p|
144
- expect(@variant.on_sale_in?(p.currency)).to be true
145
- end
146
- end
147
-
148
- end
149
-
150
- end
data/spec/spec_helper.rb DELETED
@@ -1,87 +0,0 @@
1
- # Run Coverage report
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_filter 'spec/dummy'
5
- add_group 'Controllers', 'app/controllers'
6
- add_group 'Helpers', 'app/helpers'
7
- add_group 'Mailers', 'app/mailers'
8
- add_group 'Models', 'app/models'
9
- add_group 'Views', 'app/views'
10
- add_group 'Libraries', 'lib'
11
- end
12
-
13
- # Configure Rails Environment
14
- ENV['RAILS_ENV'] = 'test'
15
-
16
- require File.expand_path('../dummy/config/environment.rb', __FILE__)
17
-
18
- require 'rspec/rails'
19
- require 'database_cleaner'
20
- require 'ffaker'
21
-
22
- # Requires supporting ruby files with custom matchers and macros, etc,
23
- # in spec/support/ and its subdirectories.
24
- Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
25
-
26
- # Requires factories and other useful helpers defined in spree_core.
27
- require 'spree/testing_support/authorization_helpers'
28
- require 'spree/testing_support/capybara_ext'
29
- require 'spree/testing_support/controller_requests'
30
- require 'spree/testing_support/factories'
31
- require 'spree/testing_support/url_helpers'
32
-
33
- # Requires factories defined in lib/spree_sale_prices/factories.rb
34
- require 'spree_sale_prices/factories'
35
-
36
- RSpec.configure do |config|
37
- config.include FactoryGirl::Syntax::Methods
38
-
39
- # Infer an example group's spec type from the file location.
40
- config.infer_spec_type_from_file_location!
41
-
42
- # == URL Helpers
43
- #
44
- # Allows access to Spree's routes in specs:
45
- #
46
- # visit spree.admin_path
47
- # current_path.should eql(spree.products_path)
48
- config.include Spree::TestingSupport::UrlHelpers
49
-
50
- # == Mock Framework
51
- #
52
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
53
- #
54
- # config.mock_with :mocha
55
- # config.mock_with :flexmock
56
- # config.mock_with :rr
57
- config.mock_with :rspec
58
- config.color = true
59
-
60
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
61
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
62
-
63
- # Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
64
- # to cleanup after each test instead. Without transactional fixtures set to false the records created
65
- # to setup a test will be unavailable to the browser, which runs under a separate server instance.
66
- config.use_transactional_fixtures = false
67
-
68
- # Ensure Suite is set to use transactions for speed.
69
- config.before :suite do
70
- DatabaseCleaner.strategy = :transaction
71
- DatabaseCleaner.clean_with :truncation
72
- end
73
-
74
- # Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
75
- config.before :each do
76
- DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
77
- DatabaseCleaner.start
78
- end
79
-
80
- # After each spec clean the database.
81
- config.after :each do
82
- DatabaseCleaner.clean
83
- end
84
-
85
- config.fail_fast = ENV['FAIL_FAST'] || false
86
- config.order = "random"
87
- end
@@ -1,28 +0,0 @@
1
- # encoding: UTF-8
2
- Gem::Specification.new do |s|
3
- s.platform = Gem::Platform::RUBY
4
- s.name = 'spree_sale_prices'
5
- s.version = '1.0.0'
6
- s.summary = 'Adds sale pricing functionality to Spree Commerce'
7
- s.description = 'Adds sale pricing functionality to Spree Commerce. It enables timed sale planning for different currencies.'
8
- s.required_ruby_version = '>= 1.9.3'
9
-
10
- s.author = 'Renuo GmbH, Jonathan Dean'
11
- s.email = 'info@renuo.ch'
12
- s.homepage = 'https://github.com/renuo/spree_sale_prices'
13
- s.license = 'BSD-3'
14
-
15
- s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.require_path = 'lib'
18
- s.requirements << 'none'
19
-
20
- s.add_dependency 'spree_core', '~> 2.4', '>= 2.4.5'
21
-
22
- s.add_development_dependency 'rspec-rails', '~> 3.1'
23
- s.add_development_dependency 'capybara', '~> 2.4'
24
- s.add_development_dependency 'database_cleaner', '~> 1.4'
25
- s.add_development_dependency 'factory_girl', '~> 4.5'
26
- s.add_development_dependency 'simplecov', '~> 0.9'
27
- s.add_development_dependency 'sqlite3', '~> 1.3'
28
- end