Permalink
Browse files

add some missing code coverage in some controllers

  • Loading branch information...
1 parent 3eb3476 commit 04cd609c7e719220f1c77776ac5da41e166aa030 @mrjabba committed May 29, 2012
@@ -8,8 +8,9 @@ def index
end
def show
- @title = "View Organization"
- @leagues = League.find_all_by_organization_id(params[:id])
+ @organization = Organization.find(params[:id])
+ @title = "View Organization | " + @organization.name
+ @leagues = @organization.leagues
end
def new
@@ -166,7 +166,14 @@
end
end
- describe "DELETE 'destroy'" do
+ describe "DELETE 'destroy'" do
#should require special admin role
end
+
+ describe "GET 'index'" do
+ it "should be successful" do
+ get :index
+ response.should be_success
+ end
+ end
end
@@ -18,5 +18,103 @@
response.should have_selector("title", :content => "New Organization")
end
end
-end
+ describe "GET 'edit'" do
+ let(:organization) { FactoryGirl.create(:organization) }
+
+ before(:each) do
+ sign_in(FactoryGirl.create(:user))
+ end
+
+ it "should be successful" do
+ get :edit, :id => organization
+ response.should be_success
+ end
+
+ it "should have the right title" do
+ get :edit, :id => organization
+ response.should have_selector("title", :content => "Edit Organization")
+ end
+ end
+
+ describe "GET 'index'" do
+ it "should be successful" do
+ get :index
+ response.should be_success
+ end
+ end
+
+ describe "GET 'show'" do
+ let(:organization) do
+ FactoryGirl.create(:organization)
+ end
+
+ it "should be successful" do
+ get :show, :id => organization
+ response.should be_success
+ end
+
+ it "should find the right organization" do
+ get :show, :id => organization
+ assigns(:organization).should == organization
+ end
+
+ it "should have the right title" do
+ get :show, :id => organization
+ response.should have_selector("title", :content => organization.name)
+ end
+
+ it "should include the organization's name" do
+ get :show, :id => organization
+ response.should have_selector("li", :content => organization.name)
+ end
+ end
+
+ describe "POST 'create'" do
+ describe "failure" do
+ let(:attr) do
+ { :name => "", :founded => ""}
+ sign_in FactoryGirl.create(:user)
+ end
+
+ it "should not create an organization" do
+ lambda do
+ post :create, :organization => attr
+ end.should_not change(Organization, :count)
+ end
+
+ it "should have the right title" do
+ post :create, :organization => attr
+ response.should have_selector("title", :content => "New Organization")
+ end
+
+ it "should render the 'new' page" do
+ post :create, :organization => attr
+ response.should render_template('new')
+ end
+ end
+
+ describe "success" do
+ let(:attr) do
+ sign_in FactoryGirl.create(:user)
+ { :name => "name", :founded => "1901"}
+ end
+
+ it "should create a organization" do
+ lambda do
+ post :create, :organization => attr
+ end.should change(Organization, :count).by(1)
+ end
+
+ it "should redirect to the organization show page" do
+ post :create, :organization => attr
+ response.should redirect_to(organization_path(assigns(:organization)))
+ end
+
+ it "should have a flash message" do
+ post :create, :organization => attr
+ flash[:success].should =~ /Organization created successfully/
+ end
+ end
+ end
+end

0 comments on commit 04cd609

Please sign in to comment.