require 'spec_helper' describe Zelda::Zender do it_should_behave_like 'a zelda base model' describe "when retrieving a list of zenders" do it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("zenders").and_return('zenders' => ['zender']) Zelda::Zender.all.should == ['zender'] end end describe "when retrieving a specific zender" do before(:each) do zender_attrs = { "zender" => {"code" => "NL1", "name" => "Nederland 1"} } Zelda::Request.stub!(:get).with("zenders/NL1").and_return zender_attrs end def find_zender Zelda::Zender.find('NL1') end it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("zenders/NL1") find_zender end it "should return a new Zender" do find_zender.should be_a(Zelda::Zender) end it "should return nil if the zender cannot be found" do Zelda::Request.stub!(:get).and_return nil find_zender.should be_nil end it "should return the correct name" do find_zender.name.should == "Nederland 1" end end describe "series" do before(:each) do @zender = Zelda::Zender.new('id' => '1') Zelda::Request.stub!(:get).and_return('zender' => {'series' => {'serie' => [{'foo' => 'bar'}]}}) end def find_series @zender.series end it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("zenders/1/series") find_series end it "should return an array of series" do find_series.first.should be_a(Zelda::Serie) end end describe "current series" do before(:each) do @zender = Zelda::Zender.new('id' => '1') Zelda::Request.stub!(:get).and_return('zender' => {'series' => {'serie' => [{'foo' => 'bar'}]}}) end def find_series @zender.current_series end it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("zenders/1/current_series") find_series end it "should return an array of series" do find_series.first.should be_a(Zelda::Serie) end end end