require 'spec_helper' describe Zelda::Serie do describe "current series" do it "calls Zelda with the correct url" do Zelda::Request.should_receive(:get).with("current_series").and_return({'series' => ['serie']}) Zelda::Serie.stub(:new).and_return('serie') Zelda::Serie.current.should == ['serie'] end it "should return an array of series" do Zelda::Request.should_receive(:get).with("series").and_return({ 'series' => ['serie'] }) Zelda::Serie.all.first.should be_a(Zelda::Serie) end end describe "when retrieving a list of series" do it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("series").and_return({ 'series' => ['serie'] }) Zelda::Serie.stub!(:new).and_return 'serie' Zelda::Serie.all.should == ['serie'] end it "should return an array of series" do Zelda::Request.should_receive(:get).with("series").and_return({ 'series' => ['serie'] }) Zelda::Serie.all.first.should be_a(Zelda::Serie) end end describe "when retrieving a specific serie" do before(:each) do serie_attrs = { "serie" => {"serie_id_nebo" => 302, "name" => "3 op reis"} } Zelda::Request.stub!(:get).with("series/1").and_return serie_attrs @aflevering = mock("Aflevering") Zelda::Aflevering.stub!(:new).and_return @aflevering end def find_serie Zelda::Serie.find(1) end it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("series/1") find_serie end it "should return a new Zender" do find_serie.should be_a(Zelda::Serie) end it "should return nil if the zender cannot be found" do Zelda::Request.stub!(:get).and_return nil find_serie.should be_nil end it "should send the correct request when asked for afleveringen" do serie = find_serie Zelda::Request.should_receive(:get).with("series/302/afleveringen").and_return("afleveringen" => ["foo"]) serie.afleveringen.should == [@aflevering] end it "should send the correct request when asked for upcoming afleveringen" do serie = find_serie Zelda::Request.should_receive(:get).with("series/302/afleveringen/upcoming").and_return("afleveringen" => ["foo"]) serie.upcoming_afleveringen.should == [@aflevering] end it "should send the correct request when asked for past afleveringen" do serie = find_serie Zelda::Request.should_receive(:get).with("series/302/afleveringen/past").and_return("afleveringen" => ["foo"]) serie.past_afleveringen.should == [@aflevering] end end it "should send the correct request when searching for series" do Zelda::Request.should_receive(:get).with("series/search/foo").and_return("series" => ["foo"]) Zelda::Serie.should_receive(:new).with("foo").and_return "foo" Zelda::Serie.search("foo").should == ["foo"] end end