Skip to content

Commit

Permalink
Adding tests for the notification of the waiting list
Browse files Browse the repository at this point in the history
  • Loading branch information
ddomingues committed Apr 2, 2015
1 parent 45c45ee commit 22d7c2f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
9 changes: 5 additions & 4 deletions app/models/spree/variant_decorator.rb
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
2 changes: 1 addition & 1 deletion lib/spree_waiting_list/factories.rb
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

Expand Down
24 changes: 21 additions & 3 deletions spec/models/spree/variant_spec.rb
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

0 comments on commit 22d7c2f

Please sign in to comment.