Skip to content

Instantly share code, notes, and snippets.

@chumpy
Created November 12, 2019 23:13
Show Gist options
  • Save chumpy/f6e08356a88248d653ff3eb5376891ed to your computer and use it in GitHub Desktop.
Save chumpy/f6e08356a88248d653ff3eb5376891ed to your computer and use it in GitHub Desktop.
test sample
require 'rails_helper'
describe StoreFront do
describe '#shows_meal_label_line?' do
let(:dc_geo) { FactoryGirl.build(:store_front, name: "DC") }
let(:other_geo) { FactoryGirl.build(:store_front) }
it 'true when multiple lines (aka DC)' do
dc_geo.lines << FactoryGirl.create(:line, name: "Paleo")
dc_geo.lines << FactoryGirl.create(:line, name: "Mix")
store_name = dc_geo.name
show_line_on_label = StoreFront.shows_meal_label_line?(store_name)
expect(show_line_on_label).to be(true)
end
it 'false when a single line' do
other_geo.lines << FactoryGirl.create(:line)
store_name = other_geo.name
show_line_on_label = StoreFront.shows_meal_label_line?(store_name)
expect(show_line_on_label).to be(false)
end
end
describe '#find_active_or_inactive' do
context "the store front is active" do
let(:store_front){ FactoryGirl.create(:store_front, active: true) }
it "finds the store front" do
expect(StoreFront.find_active_or_inactive(store_front.id)).to eql(store_front)
end
end
context "the store front is inactive" do
let(:store_front){ FactoryGirl.create(:store_front, active: false) }
it "finds the store front" do
expect(StoreFront.find_active_or_inactive(store_front.id)).to eql(store_front)
end
end
end
describe '#fully_supported_dietary_templates' do
it 'returns all active dietary template names' do
store_front = FactoryGirl.create(:store_front, :dc)
FactoryGirl.create(:dietary_template, name: "Paleo", active: true)
FactoryGirl.create(:dietary_template, name: "Whole30", active: false)
expect(store_front.fully_supported_dietary_templates).to eq ['Paleo']
end
end
describe '#available_meal_types' do
it 'returns meal types from all lines and their meal plan templates' do
store_front_01 = FactoryGirl.create(:store_front, name: "SF01", available_meal_styles: [:breakfast, :lunch, :dinner], time_zone: "Pacific Time (US & Canada)")
line_01 = FactoryGirl.create(:line, name: 'Foo')
line_02 = FactoryGirl.create(:line, name: 'Bar')
FactoryGirl.create(:meal_plan_template, line: line_01,
name: "MPT01",
meal_types: [:lunch, :dinner])
FactoryGirl.create(:meal_plan_template, line: line_02,
name: "MPT02",
meal_types: [:breakfast])
store_front_01.lines = [line_01, line_02]
expect(store_front_01.available_meal_types).to include(:breakfast)
expect(store_front_01.available_meal_types).to include(:lunch)
expect(store_front_01.available_meal_types).to include(:dinner)
store_front_02 = FactoryGirl.create(:store_front, name: "SF02", available_meal_styles: [:lunch, :dinner], time_zone: "Pacific Time (US & Canada)")
store_front_02.lines = [line_01]
expect(store_front_02.available_meal_types).not_to include(:breakfast)
expect(store_front_02.available_meal_types).to include(:lunch)
expect(store_front_02.available_meal_types).to include(:dinner)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment