-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for the notification of the waiting list
- Loading branch information
1 parent
45c45ee
commit 22d7c2f
Showing
3 changed files
with
27 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
module Spree | ||
|
||
Variant.class_eval do | ||
has_many :stock_requests | ||
|
||
def waiting_list | ||
stock_requests.notified(false) | ||
end | ||
|
||
def notify_waiting_list | ||
stock_requests.notified(false).each &:notify! | ||
product.notify_waiting_list | ||
waiting_list.each &:notify! | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
FactoryGirl.define do | ||
|
||
factory :stock_request, class: Spree::StockRequest do | ||
variant | ||
variant { |s| s.association(:base_variant) } | ||
email '[email protected]' | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
require 'spec_helper' | ||
|
||
module Spree | ||
describe Spree::Variant do | ||
let(:variant) { create(:variant) } | ||
|
||
describe Variant do | ||
context 'with stock_request' do | ||
before(:each) do | ||
create(:stock_request, variant: variant) | ||
end | ||
|
||
end | ||
it '#waiting_list' do | ||
expect(variant.waiting_list.count).to eq(1) | ||
end | ||
|
||
context '#notify_waiting_list' do | ||
it 'should notify the waiting list when some product get in the stock' do | ||
expect(variant.total_on_hand).to eq(0) | ||
expect(variant.waiting_list.count).to eq(1) | ||
|
||
stockItem = Spree::StockItem.find_by!(variant: variant) | ||
stockItem.adjust_count_on_hand(1) | ||
|
||
expect(variant.waiting_list.count).to eq(0) | ||
end | ||
end | ||
end | ||
end |