Skip to content

Commit

Permalink
Merge pull request #4 from deseretbook/fix_order_by_option_value
Browse files Browse the repository at this point in the history
DES-192: Changes `order_by_option_values` to return all variants ordered.
  • Loading branch information
dgra authored Jan 19, 2017
2 parents 65a1cb1 + 4e62d3f commit 6d4b7b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions app/models/spree/variant_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Spree::Variant.class_eval do
# Sorts by option value position and other criteria after variant position.
scope :order_by_option_value, ->{
joins(:option_values).unscope(:order).order(
left_outer_joins(:option_values)
.unscope(:order).order(
position: :asc
).order(
'spree_option_values.position ASC'
).order(
is_master: :desc,
id: :asc
).distinct
)
}

# Returns this variant's option value for its product's first option type.
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/spree/products_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
end

describe '#show' do
it 'returns only variants with option values' do
it 'returns all variants even if they dont have option values' do
product = create(:product_with_option_types)
create(:base_variant, product: product) # this has option values
create(:base_variant, product: product, option_values: [])

get :show, params: { id: product.to_param }
expect(assigns['variants'].count).to eq(1)
expect(assigns['variants'].count).to eq(3)
end
end
end

0 comments on commit 6d4b7b3

Please sign in to comment.