Created
October 29, 2012 21:40
-
-
Save chintanparikh/3976708 to your computer and use it in GitHub Desktop.
listings_controller_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Failures: | |
| 1) ListingsController#create not logged in valid attributes it should behave like Unauthorized action | |
| Failure/Error: it { should redirect_to new_user_session_path } | |
| ActionController::RoutingError: | |
| No route matches {:controller=>"listings", :action=>"create"} | |
| Shared Example Group: "Unauthorized action" called from ./spec/controllers/listings_controller_spec.rb:52 | |
| # ./spec/controllers/listings_controller_spec.rb:48:in `block (3 levels) in <top (required)>' | |
| # ./spec/support/authorization_support.rb:8:in `block (2 levels) in <top (required)>' | |
| 2) ListingsController#create logged is as a user valid attributes should create a new listing | |
| Failure/Error: subject { post :create, create_hash} | |
| ActionController::RoutingError: | |
| No route matches {:controller=>"listings", :action=>"create"} | |
| # ./spec/controllers/listings_controller_spec.rb:48:in `block (3 levels) in <top (required)>' | |
| # ./spec/controllers/listings_controller_spec.rb:64:in `block (6 levels) in <top (required)>' | |
| # ./spec/controllers/listings_controller_spec.rb:64:in `block (5 levels) in <top (required)>' | |
| 3) ListingsController#create logged is as a user valid attributes | |
| Failure/Error: subject { post :create, create_hash} | |
| ActionController::RoutingError: | |
| No route matches {:controller=>"listings", :action=>"create"} | |
| # ./spec/controllers/listings_controller_spec.rb:48:in `block (3 levels) in <top (required)>' | |
| # ./spec/controllers/listings_controller_spec.rb:66:in `block (5 levels) in <top (required)>' | |
| 4) ListingsController#create logged is as a user valid attributes | |
| Failure/Error: subject { post :create, create_hash} | |
| ActionController::RoutingError: | |
| No route matches {:controller=>"listings", :action=>"create"} | |
| # ./spec/controllers/listings_controller_spec.rb:48:in `block (3 levels) in <top (required)>' | |
| # ./spec/controllers/listings_controller_spec.rb:67:in `block (5 levels) in <top (required)>' | |
| Finished in 2.29 seconds | |
| 10 examples, 4 failures | |
| Failed examples: | |
| rspec ./spec/support/authorization_support.rb:8 # ListingsController#create not logged in valid attributes it should behave like Unauthorized action | |
| rspec ./spec/controllers/listings_controller_spec.rb:63 # ListingsController#create logged is as a user valid attributes should create a new listing | |
| rspec ./spec/controllers/listings_controller_spec.rb:66 # ListingsController#create logged is as a user valid attributes | |
| rspec ./spec/controllers/listings_controller_spec.rb:67 # ListingsController#create logged is as a user valid attributes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| describe ListingsController do | |
| let!(:category) { FactoryGirl.create(:category) } | |
| let!(:section) { FactoryGirl.create(:section, category: category) } | |
| let!(:listing) { FactoryGirl.create(:listing, section: section) } | |
| let(:user) { FactoryGirl.create(:user) } | |
| describe "#index" do | |
| subject { get :index, category_id: category.id, section_id: section.id } | |
| specify { subject.should redirect_to [category, section] } | |
| end | |
| describe "#show" do | |
| subject { get :show, category_id: category.id, section_id: section.id, id: listing.id} | |
| it "should find the target listing" do | |
| subject | |
| assigns(:listing).name.should == listing.name | |
| assigns(:listing).content.should == listing.content | |
| end | |
| end | |
| describe "#new" do | |
| subject { get :new, category_id: category.id, section_id: section.id } | |
| context "not logged in" do | |
| it_should_behave_like "Unauthorized action" | |
| end | |
| context "Logged in as a user" do | |
| before(:each) { sign_in user } | |
| it { should be_successful } | |
| it { should render_template :new } | |
| end | |
| end | |
| describe "#create" do | |
| before do | |
| @create_hash = { | |
| category_id: category.id, | |
| section_id: section.id, | |
| listing: FactoryGirl.attributes_for(:listing) | |
| } | |
| @invalid_create_hash = { | |
| category_id: category.id, | |
| section_id: section.id, | |
| listing: FactoryGirl.attributes_for(:invalid_listing) | |
| } | |
| end | |
| subject { post :create, create_hash} | |
| context "not logged in" do | |
| context "valid attributes" do | |
| let(:create_hash) { @valid_create_hash } | |
| it_should_behave_like "Unauthorized action" | |
| end | |
| context "invalid attributes" do | |
| let(:create_hash) { @invalid_create_hash } | |
| it_should_behave_like "Unauthorized action" | |
| end | |
| end | |
| context "logged is as a user" do | |
| before(:each) { sign_in user } | |
| context "valid attributes" do | |
| let(:create_hash) { @valid_create_hash } | |
| it "should create a new listing" do | |
| expect { subject }.to change(Listing, :count).by(1) | |
| end | |
| specify { subject; assigns[:listing].section_id.should == section.id } | |
| specify { subject; assigns[:listing].user_id.should == user.id } | |
| end | |
| context "invalid attributes" do | |
| let(:create_hash) { @invalid_create_hash } | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| new_user_session GET /users/sign_in(.:format) devise/sessions#new | |
| user_session POST /users/sign_in(.:format) devise/sessions#create | |
| destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy | |
| user_password POST /users/password(.:format) devise/passwords#create | |
| new_user_password GET /users/password/new(.:format) devise/passwords#new | |
| edit_user_password GET /users/password/edit(.:format) devise/passwords#edit | |
| PUT /users/password(.:format) devise/passwords#update | |
| cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel | |
| user_registration POST /users(.:format) devise/registrations#create | |
| new_user_registration GET /users/sign_up(.:format) devise/registrations#new | |
| edit_user_registration GET /users/edit(.:format) devise/registrations#edit | |
| PUT /users(.:format) devise/registrations#update | |
| DELETE /users(.:format) devise/registrations#destroy | |
| user_confirmation POST /users/confirmation(.:format) devise/confirmations#create | |
| new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new | |
| GET /users/confirmation(.:format) devise/confirmations#show | |
| category_section_listings GET /categories/:category_id/sections/:section_id/listings(.:format) listings#index | |
| POST /categories/:category_id/sections/:section_id/listings(.:format) listings#create | |
| new_category_section_listing GET /categories/:category_id/sections/:section_id/listings/new(.:format) listings#new | |
| edit_category_section_listing GET /categories/:category_id/sections/:section_id/listings/:id/edit(.:format) listings#edit | |
| category_section_listing GET /categories/:category_id/sections/:section_id/listings/:id(.:format) listings#show | |
| PUT /categories/:category_id/sections/:section_id/listings/:id(.:format) listings#update | |
| DELETE /categories/:category_id/sections/:section_id/listings/:id(.:format) listings#destroy | |
| category_sections GET /categories/:category_id/sections(.:format) sections#index | |
| POST /categories/:category_id/sections(.:format) sections#create | |
| new_category_section GET /categories/:category_id/sections/new(.:format) sections#new | |
| edit_category_section GET /categories/:category_id/sections/:id/edit(.:format) sections#edit | |
| category_section GET /categories/:category_id/sections/:id(.:format) sections#show | |
| PUT /categories/:category_id/sections/:id(.:format) sections#update | |
| DELETE /categories/:category_id/sections/:id(.:format) sections#destroy | |
| categories GET /categories(.:format) categories#index | |
| POST /categories(.:format) categories#create | |
| new_category GET /categories/new(.:format) categories#new | |
| edit_category GET /categories/:id/edit(.:format) categories#edit | |
| category GET /categories/:id(.:format) categories#show | |
| PUT /categories/:id(.:format) categories#update | |
| DELETE /categories/:id(.:format) categories#destroy | |
| new_manual_listing GET /new_listing(.:format) listings#new_manual_listing | |
| root / categories#index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment