Skip to content

Instantly share code, notes, and snippets.

@wearethefoos
Created May 11, 2016 14:46
Show Gist options
  • Save wearethefoos/cd339af9ca4ba87877e41879111e1aae to your computer and use it in GitHub Desktop.
Save wearethefoos/cd339af9ca4ba87877e41879111e1aae to your computer and use it in GitHub Desktop.
require 'rails_helper'
describe BingeSerie do
it { should validate_presence_of :title}
it { should validate_presence_of :description}
it { should validate_presence_of :image}
it { should have_many :binge_episodes}
describe "#seasons" do
let(:series) { create(:binge_serie) }
subject { series.seasons }
context "without any episodes" do
it { is_expected.to eq [] }
end
context "with a single episode" do
let(:season) { 1 }
let!(:episode) { create(:binge_episode, season: season, binge_serie: series) }
it { is_expected.to eq [ episode.season ] }
end
context "with multiple episodes" do
let(:season1) { 1 }
let(:season2) { 2 }
let(:season3) { 2 }
let!(:episodes2) { create_list(:binge_episode, 3, season: season2, binge_serie: series) }
let!(:episodes1) { create_list(:binge_episode, 3, season: season1, binge_serie: series) }
it "orders the seasons and returns a unique list" do
is_expected.to eq [ season1, season2 ]
end
it "does not contain seasons from episodes that are not part of this series" do
create_list(:binge_episode, 3, season: 3)
is_expected.to eq [ season1, season2 ]
is_expected.not_to include(3)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment