Created
October 11, 2012 06:26
-
-
Save chintanparikh/3870576 to your computer and use it in GitHub Desktop.
Controller and Spec file
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
# --- SPEC FILE ---- | |
describe "#create" do | |
before do | |
@create_hash = { | |
category_id: category.id, | |
section_id: section.id, | |
listing: FactoryGirl.attributes_for(:listing) | |
} | |
end | |
subject { post :create, @create_hash} | |
context "not logged in" do | |
it_should_behave_like "Unauthorized action" | |
end | |
context "Logged is as a user" do | |
before(:each) { sign_in user } | |
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 } | |
end | |
end | |
# ---- CONTROLLER ACTION ---- | |
def create | |
@listing = Section.find(params[:section_id]).listings.create(params[:listing]) | |
@listing.user = current_user | |
@listing.save | |
respond_with [@listing.section.category, @listing.section, @listing] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment