spree_zero_stock_products 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ad3df76675515354b52c60af398f0ca74908a53
4
+ data.tar.gz: c4918e30f68ef32b1d4c588cec5714b5f2de4868
5
+ SHA512:
6
+ metadata.gz: c4d5340c1f2e73075193d10952e6226eba34bf04a90f74a506cafc83adb807af118b1e0976ffe2168b5f40506d3992720723ae7a18cf0d0980ad4541516fa5fa
7
+ data.tar.gz: 0523fc527d6bb5272579809826ce5c385e03aa39344ff271b88f0f75e8f6feeabec37388367fd862f73f2d6458644aa3495570852af9adf977e7ff64b41b82d0
data/.gitignore CHANGED
@@ -13,3 +13,4 @@ pkg
13
13
  *.swp
14
14
  spec/dummy
15
15
  .ruby*
16
+ doc/
data/.travis.yml CHANGED
@@ -6,10 +6,18 @@ rvm:
6
6
  - 1.9.3
7
7
  - 2.0.0
8
8
  - ruby-head
9
+ - jruby-19mode
10
+ env:
11
+ - DB=sqlite
12
+ - DB=mysql
13
+ - DB=postgres
9
14
  language: ruby
10
15
  matrix:
11
16
  allow_failures:
12
17
  - rvm: ruby-head
18
+ exclude:
19
+ - rvm: jruby-19mode
20
+ env: DB=mysql
13
21
  notifications:
14
22
  recipients:
15
23
  - swrobel@gmail.com
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Spree Zero Stock Products Changelog
2
+
3
+ ## 2.0.1
4
+
5
+ * Backorderable products will now be shown even if `show_zero_stock_products = false`
6
+ * Using durable_decorator by @jumph4x to DRY-up method overrides & warn about changes to overridden code
7
+ * Tested against jruby, postgres & mysql
8
+
9
+ ## 2.0.0
10
+ Initial release
data/Gemfile CHANGED
@@ -1,3 +1,15 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ platforms :jruby do
4
+ gem 'activerecord-jdbcsqlite3-adapter'
5
+ gem 'activerecord-jdbcpostgresql-adapter'
6
+ gem 'activerecord-jdbcmysql-adapter'
7
+ end
8
+
9
+ platforms :ruby do
10
+ gem 'sqlite3'
11
+ gem 'pg'
12
+ gem 'mysql2'
13
+ end
14
+
3
15
  gemspec
data/README.md CHANGED
@@ -34,6 +34,20 @@ Profit.
34
34
 
35
35
  Testing
36
36
  -------
37
+ This extension is tested against the following rubies:
38
+
39
+ * 1.9.3
40
+ * 2.0.0
41
+ * jruby-19mode (but not w/ mysql until bug is fixed)
42
+ * ruby-head (Travis failures allowed)
43
+
44
+ As well as the following databases:
45
+
46
+ * sqlite
47
+ * postgres
48
+ * mysql
49
+
50
+ ### Running the tests locally
37
51
 
38
52
  Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
39
53
 
@@ -1,5 +1,22 @@
1
1
  Spree::Product.class_eval do
2
+ # Returns only products that are in stock or backorderable
2
3
  add_search_scope :on_hand do
3
- where("#{table_name}.id IN (SELECT product_id FROM #{Spree::Variant.table_name} v JOIN #{Spree::StockItem.table_name} i ON v.id = i.variant_id WHERE deleted_at IS NULL GROUP BY product_id HAVING SUM(count_on_hand) > 0)")
4
+ where(
5
+ <<-SQL
6
+ #{table_name}.id IN
7
+ (
8
+ SELECT product_id FROM #{Spree::Variant.table_name} v
9
+ JOIN #{Spree::StockItem.table_name} i
10
+ ON v.id = i.variant_id
11
+ WHERE deleted_at IS NULL
12
+ GROUP BY product_id
13
+ HAVING SUM(count_on_hand) > 0
14
+ OR MAX(CASE backorderable
15
+ WHEN #{ActiveRecord::Base.connection.quoted_true} THEN 1
16
+ ELSE 0
17
+ END) > 0
18
+ )
19
+ SQL
20
+ )
4
21
  end
5
22
  end
@@ -1,12 +1,11 @@
1
1
  Spree::Core::Search::Base.class_eval do
2
2
 
3
3
  protected
4
- def get_base_scope
5
- base_scope = Spree::Product.active
6
- base_scope = base_scope.in_taxon(taxon) unless taxon.blank?
7
- base_scope = get_products_conditions_for(base_scope, keywords)
8
- base_scope = base_scope.on_hand unless Spree::Config[:show_zero_stock_products]
9
- base_scope = add_search_scopes(base_scope)
10
- base_scope
4
+ durably_decorate :get_base_scope, mode: 'soft', sha: '0030f517d06459bfcde9ae18157806c3b702a71f' do
5
+ if Spree::Config[:show_zero_stock_products]
6
+ original_get_base_scope
7
+ else
8
+ original_get_base_scope.on_hand
9
+ end
11
10
  end
12
11
  end
@@ -1,7 +1,10 @@
1
1
  Spree::Taxon.class_eval do
2
- def active_products
3
- scope = products.active
4
- scope = scope.on_hand unless Spree::Config[:show_zero_stock_products]
5
- scope
2
+ # Returns products in this taxon that are active (and in stock, depending on settings)
3
+ durably_decorate :active_products, mode: 'soft', sha: 'd2da9b539628597db39f535ea8aa2da241d61881' do
4
+ if Spree::Config[:show_zero_stock_products]
5
+ original_active_products
6
+ else
7
+ original_active_products.on_hand
8
+ end
6
9
  end
7
10
  end
@@ -17,7 +17,7 @@ module SpreeZeroStockProducts
17
17
  end
18
18
  end
19
19
 
20
- def self.activate
20
+ def self.activate #:nodoc:
21
21
  Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
22
22
  Rails.configuration.cache_classes ? require(c) : load(c)
23
23
  end
@@ -1,2 +1,3 @@
1
1
  require 'spree_core'
2
+ require 'durable_decorator'
2
3
  require 'spree_zero_stock_products/engine'
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Spree::Core::Search::Base do
4
4
 
5
5
  before do
6
- stock_location = create(:stock_location)
6
+ stock_location = create(:stock_location, backorderable_default: false)
7
7
  @product_with_stock = create(:product)
8
8
  @product_out_of_stock = create(:product)
9
9
 
@@ -17,10 +17,11 @@ describe Spree::Core::Search::Base do
17
17
  Spree::Config[:show_zero_stock_products] = false
18
18
  end
19
19
 
20
- it "returns all products by default" do
20
+ it "returns only in stock products" do
21
21
  params = { :per_page => "" }
22
22
  searcher = Spree::Core::Search::Base.new(params)
23
- searcher.retrieve_products.count.should == 1
23
+ searcher.retrieve_products.should include @product_with_stock
24
+ searcher.retrieve_products.should_not include @product_out_of_stock
24
25
  end
25
26
  end
26
27
 
@@ -30,10 +31,11 @@ describe Spree::Core::Search::Base do
30
31
  Spree::Config[:show_zero_stock_products] = true
31
32
  end
32
33
 
33
- it "returns all products by default" do
34
+ it "returns all products regardless of stock status" do
34
35
  params = { :per_page => "" }
35
36
  searcher = Spree::Core::Search::Base.new(params)
36
- searcher.retrieve_products.count.should == 2
37
+ searcher.retrieve_products.should include @product_with_stock
38
+ searcher.retrieve_products.should include @product_out_of_stock
37
39
  end
38
40
  end
39
41
  end
@@ -4,12 +4,17 @@ describe "Product scopes" do
4
4
 
5
5
  context "with scope on_hand" do
6
6
  before do
7
- stock_location = create(:stock_location)
7
+ stock_location = create(:stock_location, backorderable_default: false)
8
+
8
9
  @product_with_stock = create(:product)
10
+ stock_location.stock_items.where(variant_id: @product_with_stock.master.id).first.adjust_count_on_hand(10)
11
+
9
12
  @product_out_of_stock = create(:product)
13
+ stock_location.stock_items.where(variant_id: @product_out_of_stock.master.id).first.adjust_count_on_hand(0)
10
14
 
11
- stock_location.stock_items.where(:variant_id => @product_with_stock.master.id).first.adjust_count_on_hand(10)
12
- stock_location.stock_items.where(:variant_id => @product_out_of_stock.master.id).first.adjust_count_on_hand(0)
15
+ @product_backorderable = create(:product)
16
+ stock_location.stock_items.where(variant_id: @product_backorderable.master.id).first.adjust_count_on_hand(0)
17
+ stock_location.stock_items.where(variant_id: @product_backorderable.master.id).first.update_attribute(:backorderable, true)
13
18
  end
14
19
 
15
20
  it "includes a product with available stock" do
@@ -19,5 +24,9 @@ describe "Product scopes" do
19
24
  it "excludes a product without available stock" do
20
25
  Spree::Product.on_hand.should_not include @product_out_of_stock
21
26
  end
27
+
28
+ it "includes a product without stock that is backorderable" do
29
+ Spree::Product.on_hand.should include @product_backorderable
30
+ end
22
31
  end
23
32
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Spree::Taxon do
4
4
 
5
5
  before do
6
- stock_location = create(:stock_location)
6
+ stock_location = create(:stock_location, backorderable_default: false)
7
7
  @product_with_stock = create(:product)
8
8
  @product_out_of_stock = create(:product)
9
9
 
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,15 @@
1
- # Run Coverage report
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_group 'Controllers', 'app/controllers'
5
- add_group 'Helpers', 'app/helpers'
6
- add_group 'Mailers', 'app/mailers'
7
- add_group 'Models', 'app/models'
8
- add_group 'Views', 'app/views'
9
- add_group 'Libraries', 'lib'
1
+ unless ENV['TRAVIS']
2
+ # Run Coverage report
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter 'spec/dummy'
6
+ add_group 'Controllers', 'app/controllers'
7
+ add_group 'Helpers', 'app/helpers'
8
+ add_group 'Mailers', 'app/mailers'
9
+ add_group 'Models', 'app/models'
10
+ add_group 'Views', 'app/views'
11
+ add_group 'Libraries', 'lib'
12
+ end
10
13
  end
11
14
 
12
15
  # Configure Rails Environment
@@ -15,7 +18,6 @@ ENV['RAILS_ENV'] = 'test'
15
18
  require File.expand_path('../dummy/config/environment.rb', __FILE__)
16
19
 
17
20
  require 'rspec/rails'
18
- require 'database_cleaner'
19
21
  require 'ffaker'
20
22
 
21
23
  # Requires supporting ruby files with custom matchers and macros, etc,
@@ -44,27 +46,7 @@ RSpec.configure do |config|
44
46
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
45
47
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
46
48
 
47
- # Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
48
- # to cleanup after each test instead. Without transactional fixtures set to false the records created
49
- # to setup a test will be unavailable to the browser, which runs under a seperate server instance.
50
- config.use_transactional_fixtures = false
51
-
52
- # Ensure Suite is set to use transactions for speed.
53
- config.before :suite do
54
- DatabaseCleaner.strategy = :transaction
55
- DatabaseCleaner.clean_with :truncation
56
- end
57
-
58
- # Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
59
- config.before :each do
60
- DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
61
- DatabaseCleaner.start
62
- end
63
-
64
- # After each spec clean the database.
65
- config.after :each do
66
- DatabaseCleaner.clean
67
- end
49
+ config.use_transactional_fixtures = true
68
50
 
69
51
  config.fail_fast = ENV['FAIL_FAST'] || false
70
52
  end
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  s.platform = Gem::Platform::RUBY
4
4
  s.name = 'spree_zero_stock_products'
5
- s.version = '2.0.0'
5
+ s.version = '2.0.1'
6
6
  s.summary = 'Restore show_zero_stock_products functionality in Spree 2.0+'
7
7
  s.description = 'Restore show_zero_stock_products functionality in Spree 2.0+'
8
8
  s.required_ruby_version = '>= 1.9.3'
@@ -18,11 +18,11 @@ Gem::Specification.new do |s|
18
18
  s.requirements << 'none'
19
19
 
20
20
  s.add_dependency 'spree_core', '~> 2.0.0'
21
+ s.add_dependency 'durable_decorator', '~> 0.2.0'
21
22
 
22
- s.add_development_dependency 'database_cleaner', '< 1.1.0' # >= 1.1.0 is broken w/ SQLite3 https://github.com/bmabey/database_cleaner/issues/224
23
23
  s.add_development_dependency 'factory_girl', '~> 4.2'
24
24
  s.add_development_dependency 'ffaker'
25
25
  s.add_development_dependency 'rspec-rails', '~> 2.13'
26
26
  s.add_development_dependency 'simplecov'
27
- s.add_development_dependency 'sqlite3'
27
+ s.add_development_dependency 'durable_decorator_rails', '~> 0.1.0'
28
28
  end
metadata CHANGED
@@ -1,128 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_zero_stock_products
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 2.0.0
4
+ version: 2.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stefan Wrobel
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-19 00:00:00.000000000 Z
11
+ date: 2013-09-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: spree_core
16
- version_requirements: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 2.0.0
22
15
  requirement: !ruby/object:Gem::Requirement
23
- none: false
24
16
  requirements:
25
17
  - - ~>
26
18
  - !ruby/object:Gem::Version
27
19
  version: 2.0.0
28
20
  type: :runtime
29
21
  prerelease: false
30
- - !ruby/object:Gem::Dependency
31
- name: database_cleaner
32
22
  version_requirements: !ruby/object:Gem::Requirement
33
- none: false
34
23
  requirements:
35
- - - <
24
+ - - ~>
36
25
  - !ruby/object:Gem::Version
37
- version: 1.1.0
26
+ version: 2.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: durable_decorator
38
29
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
30
  requirements:
41
- - - <
31
+ - - ~>
42
32
  - !ruby/object:Gem::Version
43
- version: 1.1.0
44
- type: :development
33
+ version: 0.2.0
34
+ type: :runtime
45
35
  prerelease: false
46
- - !ruby/object:Gem::Dependency
47
- name: factory_girl
48
36
  version_requirements: !ruby/object:Gem::Requirement
49
- none: false
50
37
  requirements:
51
38
  - - ~>
52
39
  - !ruby/object:Gem::Version
53
- version: '4.2'
40
+ version: 0.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: factory_girl
54
43
  requirement: !ruby/object:Gem::Requirement
55
- none: false
56
44
  requirements:
57
45
  - - ~>
58
46
  - !ruby/object:Gem::Version
59
47
  version: '4.2'
60
48
  type: :development
61
49
  prerelease: false
62
- - !ruby/object:Gem::Dependency
63
- name: ffaker
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
- none: false
66
51
  requirements:
67
- - - ! '>='
52
+ - - ~>
68
53
  - !ruby/object:Gem::Version
69
- version: '0'
54
+ version: '4.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ffaker
70
57
  requirement: !ruby/object:Gem::Requirement
71
- none: false
72
58
  requirements:
73
- - - ! '>='
59
+ - - '>='
74
60
  - !ruby/object:Gem::Version
75
61
  version: '0'
76
62
  type: :development
77
63
  prerelease: false
78
- - !ruby/object:Gem::Dependency
79
- name: rspec-rails
80
64
  version_requirements: !ruby/object:Gem::Requirement
81
- none: false
82
65
  requirements:
83
- - - ~>
66
+ - - '>='
84
67
  - !ruby/object:Gem::Version
85
- version: '2.13'
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
86
71
  requirement: !ruby/object:Gem::Requirement
87
- none: false
88
72
  requirements:
89
73
  - - ~>
90
74
  - !ruby/object:Gem::Version
91
75
  version: '2.13'
92
76
  type: :development
93
77
  prerelease: false
94
- - !ruby/object:Gem::Dependency
95
- name: simplecov
96
78
  version_requirements: !ruby/object:Gem::Requirement
97
- none: false
98
79
  requirements:
99
- - - ! '>='
80
+ - - ~>
100
81
  - !ruby/object:Gem::Version
101
- version: '0'
82
+ version: '2.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
102
85
  requirement: !ruby/object:Gem::Requirement
103
- none: false
104
86
  requirements:
105
- - - ! '>='
87
+ - - '>='
106
88
  - !ruby/object:Gem::Version
107
89
  version: '0'
108
90
  type: :development
109
91
  prerelease: false
110
- - !ruby/object:Gem::Dependency
111
- name: sqlite3
112
92
  version_requirements: !ruby/object:Gem::Requirement
113
- none: false
114
93
  requirements:
115
- - - ! '>='
94
+ - - '>='
116
95
  - !ruby/object:Gem::Version
117
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: durable_decorator_rails
118
99
  requirement: !ruby/object:Gem::Requirement
119
- none: false
120
100
  requirements:
121
- - - ! '>='
101
+ - - ~>
122
102
  - !ruby/object:Gem::Version
123
- version: '0'
103
+ version: 0.1.0
124
104
  type: :development
125
105
  prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.1.0
126
111
  description: Restore show_zero_stock_products functionality in Spree 2.0+
127
112
  email: swrobel@gmail.com
128
113
  executables: []
@@ -132,6 +117,7 @@ files:
132
117
  - .gitignore
133
118
  - .rspec
134
119
  - .travis.yml
120
+ - CHANGELOG.md
135
121
  - Gemfile
136
122
  - LICENSE
137
123
  - README.md
@@ -154,28 +140,27 @@ files:
154
140
  homepage: https://github.com/swrobel/spree_zero_stock_products
155
141
  licenses:
156
142
  - MIT
143
+ metadata: {}
157
144
  post_install_message:
158
145
  rdoc_options: []
159
146
  require_paths:
160
147
  - lib
161
148
  required_ruby_version: !ruby/object:Gem::Requirement
162
- none: false
163
149
  requirements:
164
- - - ! '>='
150
+ - - '>='
165
151
  - !ruby/object:Gem::Version
166
152
  version: 1.9.3
167
153
  required_rubygems_version: !ruby/object:Gem::Requirement
168
- none: false
169
154
  requirements:
170
- - - ! '>='
155
+ - - '>='
171
156
  - !ruby/object:Gem::Version
172
157
  version: '0'
173
158
  requirements:
174
159
  - none
175
160
  rubyforge_project:
176
- rubygems_version: 1.8.25
161
+ rubygems_version: 2.0.3
177
162
  signing_key:
178
- specification_version: 3
163
+ specification_version: 4
179
164
  summary: Restore show_zero_stock_products functionality in Spree 2.0+
180
165
  test_files:
181
166
  - spec/lib/search/base_spec.rb