require 'spec_helper' describe Zelda::Omroep do before do @model = Zelda::Omroep.new(:foo => "bar") end it_should_behave_like 'a zelda base model' describe "when retrieving a list of omroepen" do it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("omroepen").and_return('omroepen' => ['omroep']) Zelda::Omroep.all.should == ['omroep'] end end describe "when retrieving a specific omroep" do before(:each) do omroep_attrs = { "omroep" => {"slug" => "kro", "name" => "KRO"} } Zelda::Request.stub!(:get).with("omroepen/kro").and_return omroep_attrs end def find_omroep Zelda::Omroep.find('kro') end it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("omroepen/kro") find_omroep end it "should return a new Omroep" do find_omroep.should be_a(Zelda::Omroep) end it "should return nil if the omroep cannot be found" do Zelda::Request.stub!(:get).and_return nil find_omroep.should be_nil end it "should return the correct slug" do find_omroep.slug.should == "kro" end it "should return the correct name" do find_omroep.name.should == "KRO" end end describe "series" do before(:each) do @omroep = Zelda::Omroep.new('slug' => 'kro') Zelda::Request.stub!(:get).and_return('omroep' => {'series' => {'serie' => [{'foo' => 'bar'}]}}) end def find_series @omroep.series end it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("omroepen/kro/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 @omroep = Zelda::Omroep.new('slug' => 'kro') Zelda::Request.stub!(:get).and_return('omroep' => {'series' => {'serie' => [{'foo' => 'bar'}]}}) end def find_series @omroep.current_series end it "should call Zelda with the correct url" do Zelda::Request.should_receive(:get).with("omroepen/kro/current_series") find_series end it "should return an array of series" do find_series.first.should be_a(Zelda::Serie) end end end