Skip to content

Commit

Permalink
Merge pull request joshnuss#4 from farneman/3-0-stable
Browse files Browse the repository at this point in the history
Updated for Spree 3.0 stable branch
  • Loading branch information
joshnuss committed Apr 1, 2015
2 parents b16de77 + c3dbc08 commit ac4c663
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

# Provides basic authentication functionality for testing parts of your engine
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-2-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'

gemspec
4 changes: 2 additions & 2 deletions app/models/concerns/stock_notification.rb
Expand Up @@ -10,13 +10,13 @@ module StockNotification
def notify_out_of_stock
out_of_stock = crossed(0)
yield
StockMailer.out_of_stock(self).deliver if out_of_stock
StockMailer.out_of_stock(self).deliver_later if out_of_stock
end

def notify_low_stock
low_stock = crossed(Spree::Config.low_stock_threshold)
yield
StockMailer.low_stock(self).deliver if low_stock
StockMailer.low_stock(self).deliver_later if low_stock
end

def crossed(threshold)
Expand Down
@@ -1,11 +1,15 @@
Spree.config do |config|
# create a list of admin emails
admin_role = Spree::Role.find_by_name('admin')
admin_emails = admin_role.users.map(&:email).join(',')
# ==> Stock Notifications List
# Supply a comma-separated list of emails to get notifications:
# config.stock_notifications_list = "jack@example.com,jill@example.com"

# set comma separated list of emails
config.stock_notifications_list = admin_emails
# In a typical Spree app this can be accomplished with the following:
# admin_role = Spree::Role.find_by_name('admin')
# admin_emails = admin_role.users.map(&:email).join(',')
# config.stock_notifications_list = admin_emails

# when stock level reaches the "low stock threshold", admins will be notified. Default is 1
config.low_stock_threshold = 2
# ==> Low Stock Threshold
# When stock level reaches the "low stock threshold", admins will be
# notified. Default is 1.
# config.low_stock_threshold = 1
end
4 changes: 2 additions & 2 deletions spec/mailers/stock_mailer_spec.rb
@@ -1,5 +1,5 @@
require "spec_helper"

describe StockMailer do
pending "add some examples to (or delete) #{__FILE__}"
describe StockMailer, :type => :mailer do
skip "add some examples to (or delete) #{__FILE__}"
end
16 changes: 10 additions & 6 deletions spec/models/stock_item_spec.rb
@@ -1,13 +1,17 @@
require 'spec_helper'

describe Spree::StockItem do
describe Spree::StockItem, type: :model do
let(:variant) { create(:variant) }
let(:stock_item) { variant.stock_items.first}
let(:mail) { double(:mail) }

before do
Spree::Config.stock_notifications_list = "jack@example.com,jill@example.com"
end

it "sends notification when out of stock" do
StockMailer.should_receive(:out_of_stock).once.with(stock_item).and_return(mail)
mail.should_receive(:deliver)
expect(StockMailer).to receive(:low_stock).once.with(stock_item).and_return(mail)
expect(mail).to receive(:deliver_later)

stock_item.adjust_count_on_hand(10)
stock_item.adjust_count_on_hand(-5)
Expand All @@ -17,8 +21,8 @@
it "sends notification when low stock" do
Spree::Config.low_stock_threshold = 5

StockMailer.should_receive(:low_stock).once.with(stock_item).and_return(mail)
mail.should_receive(:deliver)
expect(StockMailer).to receive(:low_stock).once.with(stock_item).and_return(mail)
expect(mail).to receive(:deliver_later)

stock_item.adjust_count_on_hand(10)
stock_item.adjust_count_on_hand(-3)
Expand All @@ -28,7 +32,7 @@
it "doesnt sends notification when low stock threshold is nil" do
Spree::Config.low_stock_threshold = nil

StockMailer.should_not_receive(:low_stock)
expect(StockMailer).not_to receive(:low_stock)

stock_item.adjust_count_on_hand(10)
stock_item.adjust_count_on_hand(-3)
Expand Down
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -32,6 +32,7 @@
# Requires factories defined in lib/spree_stock_notifications/factories.rb
require 'spree_stock_notifications/factories'


RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods

Expand All @@ -53,6 +54,8 @@
config.mock_with :rspec
config.color = true

config.infer_spec_type_from_file_location!

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

Expand All @@ -68,7 +71,7 @@
end

# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
config.before :each do
config.before :each do |example|
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
DatabaseCleaner.start
end
Expand Down
18 changes: 10 additions & 8 deletions spree_stock_notifications.gemspec
@@ -1,11 +1,13 @@
# encoding: UTF-8
version = '3.0.0'

Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_stock_notifications'
s.version = '2.2.0'
s.version = version
s.summary = 'Stock notifications'
s.description = 'Notifies when stock levels are low or item goes out of stock'
s.required_ruby_version = '>= 1.9.3'
s.required_ruby_version = '>= 2.0.0'

s.author = 'Joshua Nussbaum'
s.email = 'joshnuss@gmail.com'
Expand All @@ -16,15 +18,15 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency 'spree_core', '~> 2.2.0'
s.add_dependency 'spree_backend'
s.add_dependency 'spree_core', version
s.add_dependency 'spree_backend', version

s.add_development_dependency 'capybara', '~> 2.1'
s.add_development_dependency 'capybara', '~> 2.4'
s.add_development_dependency 'coffee-rails'
s.add_development_dependency 'database_cleaner'
s.add_development_dependency 'factory_girl', '~> 4.2'
s.add_development_dependency 'database_cleaner', '~> 1.4'
s.add_development_dependency 'factory_girl', '~> 4.5'
s.add_development_dependency 'ffaker'
s.add_development_dependency 'rspec-rails', '~> 2.13'
s.add_development_dependency 'rspec-rails', '~> 3.2'
s.add_development_dependency 'sass-rails'
s.add_development_dependency 'selenium-webdriver'
s.add_development_dependency 'simplecov'
Expand Down

0 comments on commit ac4c663

Please sign in to comment.