Skip to content

Commit

Permalink
Refactored specs to make more readable as well as removing non essent…
Browse files Browse the repository at this point in the history
…ai specs.
  • Loading branch information
baphled committed Aug 5, 2010
1 parent ae125e3 commit 3aa529b
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions spec/controllers/parking_controller_spec.rb
Expand Up @@ -3,7 +3,7 @@
describe ParkingController do
describe "GET, tickets" do
context "requesting a list of tickets" do
it "should do a search using the LightHouse API for tags" do
it "can get tickets from Lighthouse" do
@resource = mock_model(Resource, :name => "baphled", :project => '50164').as_null_object
Resource.stub!(:find).and_return @resource
@resource.should_receive(:tickets).with("feature")
Expand All @@ -13,7 +13,7 @@
end

describe "GET, new" do
it "should create a new resource model" do
it "creates a new resource model" do
Resource.should_receive(:new)
get :new
end
Expand All @@ -31,12 +31,12 @@
post :create
end

it "should save the new resource" do
it "saves the new resource" do
@resource.should_receive(:save)
post :create, {:resource => @resource}
end

it "should redirect to the parking index view" do
it "redirects to the parking page" do
@resource.stub!(:save).and_return true
post :create, {:resource => @resource}
response.should redirect_to parking_index_path
Expand All @@ -48,56 +48,57 @@
before(:each) do
Resource.stub!(:find).and_return mock_model(Resource, :id => 1).as_null_object
end
context "imports successful" do

it "should get each tickets content and create a parked item" do
context "successfully imports" do
it "creates a parked items from tickets" do
LightHouse.should_receive(:create)
post :import, {:lighthouse =>{:ticket_id => ["9"]}, :resource => {:id => 1}}
end

it "should display a flash message" do
it "displays a flash message" do
post :import, {:lighthouse =>{:ticket_id => ["9"]}, :resource => {:id => 1}}
flash[:notice].should contain 'Parked tickets'
flash[:notice].should_not be_empty
end

it "should redirect to the parking index page" do
it "redirects to the parking page" do
post :import, {:lighthouse =>{:ticket_id => ["9"]}, :resource => {:id => 1}}
response.should redirect_to parking_index_path
end

it "should save the tickets content body" do
it "saves the ticket's content body" do
post :import, {:lighthouse =>{:ticket_id => ["9"]}, :resource => {:id => 1}}
Resource.first.body.should_not be_nil
end

it "should save the tickets title" do
it "saves the ticket's title" do
post :import, {:lighthouse =>{:ticket_id => ["9"]}, :resource => {:id => 1}}
Resource.first.title.should_not be_nil
end
end

context "imports fail" do
context "failing imports" do

context "with one resource" do
before(:each) do
LightHouse.stub!(:create).and_return false
post :import, {:lighthouse =>{:ticket_id => ["9", "41"]}, :resource => {:id => 1}}
end

it "should display a flash message" do
it "displays a flash message" do
flash[:error].should contain "Unable to save tickets"
end

it "should render the tickets page again" do
it "displays the tickets page" do
response.should redirect_to parking_index_path
end
end
end
end

describe "GET, unique-resource-name" do
context "is not unique" do
context "not unique" do
before(:each) do
Resource.create({:name => 'baphled', :project => '50164'})
Resource.make
end

it "returns an error message" do
Expand Down

0 comments on commit 3aa529b

Please sign in to comment.