Created
October 13, 2017 13:12
-
-
Save ArnoHolo/54b9259fbaa067d7abbf04a73d94ec40 to your computer and use it in GitHub Desktop.
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
# Rspec test (with FactoryGirl) for Stackoverflow question https://stackoverflow.com/questions/46728121 | |
describe 'with_ingredients' do | |
subject { Cocktail.with_ingredients(ingredient_ids) } | |
context 'one cocktail, one ingredient, zero cocktail ingredient' do | |
let(:cocktail) { create :cocktail } | |
let(:ingredient) { create :ingredient } | |
let(:ingredient_ids) { [ingredient.id] } | |
before { create :cocktail_ingredient, cocktail: cocktail } | |
it { is_expected.to eq [] } | |
end | |
context 'one cocktail, one ingredient' do | |
let(:cocktail) { create :cocktail } | |
let(:ingredient) { create :ingredient } | |
let(:ingredient_ids) { [ingredient.id] } | |
before { create :cocktail_ingredient, cocktail: cocktail, ingredient: ingredient } | |
it { is_expected.to eq [cocktail] } | |
end | |
context 'three cocktails, two ingredients' do | |
let(:cocktail) { create :cocktail } | |
let(:cocktail2) { create :cocktail } | |
let(:cocktail3) { create :cocktail } | |
let(:ingredient) { create :ingredient } | |
let(:ingredient2) { create :ingredient } | |
let(:ingredient_ids) { [ingredient.id, ingredient2.id] } | |
before do | |
create :ingredient | |
create :cocktail_ingredient | |
create :cocktail_ingredient, cocktail: cocktail, ingredient: ingredient | |
create :cocktail_ingredient, cocktail: cocktail2, ingredient: ingredient | |
create :cocktail_ingredient, cocktail: cocktail, ingredient: ingredient2 | |
create :cocktail_ingredient, cocktail: cocktail3, ingredient: ingredient2 | |
end | |
it { is_expected.to eq [cocktail] } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment