|
7 | 7 | let!(:variant_1) { create(:variant, product: product) } |
8 | 8 | let!(:variant_2) { create(:variant, product: product) } |
9 | 9 |
|
10 | | - context ".with_prices" do |
| 10 | + describe ".with_prices" do |
11 | 11 | context "when searching for the default pricing options" do |
12 | 12 | it "finds all variants" do |
13 | 13 | expect(Spree::Variant.with_prices).to contain_exactly(product.master, variant_1, variant_2) |
|
44 | 44 | end |
45 | 45 | end |
46 | 46 |
|
47 | | - it ".descend_by_popularity" do |
| 47 | + specify ".descend_by_popularity" do |
48 | 48 | # Requires a product with at least two variants, where one has a higher number of |
49 | 49 | # orders than the other |
50 | 50 | Spree::LineItem.delete_all # FIXME leaky database - too many line_items |
51 | 51 | create(:line_item, variant: variant_1) |
52 | 52 | expect(Spree::Variant.descend_by_popularity.first).to eq(variant_1) |
53 | 53 | end |
54 | 54 |
|
55 | | - context "finding by option values" do |
| 55 | + describe ".by_stock_location" do |
| 56 | + let!(:stock_location_1) { create(:stock_location) } |
| 57 | + let!(:stock_location_2) { create(:stock_location) } |
| 58 | + |
| 59 | + it "finds variants by stock location" do |
| 60 | + variants = Spree::Variant.where(id: [variant_1.id, variant_2.id]) # exclude the master variant |
| 61 | + variant_1.stock_items.where.not(stock_location_id: stock_location_1.id).delete_all |
| 62 | + variant_2.stock_items.where.not(stock_location_id: stock_location_2.id).delete_all |
| 63 | + |
| 64 | + expect(variants.by_stock_location(stock_location_1.id)).to contain_exactly(variant_1) |
| 65 | + expect(variants.by_stock_location(stock_location_2.id)).to contain_exactly(variant_2) |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + describe ".has_option" do |
56 | 70 | let!(:option_type) { create(:option_type, name: "bar") } |
57 | 71 | let!(:option_value_1) do |
58 | 72 | option_value = create(:option_value, name: "foo", option_type: option_type) |
|
68 | 82 |
|
69 | 83 | let!(:product_variants) { product.variants_including_master } |
70 | 84 |
|
71 | | - it "by objects" do |
| 85 | + it "finds by option value objects" do |
72 | 86 | variants = product_variants.has_option(option_type, option_value_1) |
| 87 | + |
73 | 88 | expect(variants).to include(variant_1) |
74 | 89 | expect(variants).not_to include(variant_2) |
75 | 90 | end |
76 | 91 |
|
77 | | - it "by names" do |
| 92 | + it "finds by option value names" do |
78 | 93 | variants = product_variants.has_option("bar", "foo") |
| 94 | + |
79 | 95 | expect(variants).to include(variant_1) |
80 | 96 | expect(variants).not_to include(variant_2) |
81 | 97 | end |
82 | 98 |
|
83 | | - it "by ids" do |
| 99 | + it "finds by option value ids" do |
84 | 100 | variants = product_variants.has_option(option_type.id, option_value_1.id) |
| 101 | + |
85 | 102 | expect(variants).to include(variant_1) |
86 | 103 | expect(variants).not_to include(variant_2) |
87 | 104 | end |
88 | 105 |
|
89 | | - it "by mixed conditions" do |
| 106 | + it "finds by option value with mixed conditions" do |
90 | 107 | variants = product_variants.has_option(option_type.id, "foo", option_value_2) |
| 108 | + |
91 | 109 | expect(variants).to be_empty |
92 | 110 | end |
93 | 111 | end |
|
0 commit comments