Created
April 23, 2013 23:18
-
-
Save karmiclychee/5448251 to your computer and use it in GitHub Desktop.
This file contains 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" | |
feature "Creating Items" do | |
user = FactoryGirl.create(:user_confirmed) | |
collection = FactoryGirl.create(:collection, profile: user.profile) | |
project = FactoryGirl.create(:project, collection: collection, profile: user.profile) | |
item = FactoryGirl.build(:item, project: project) | |
before do | |
sign_in_as!(user) | |
visit "/" | |
click_link collection.name | |
click_link project.name | |
end | |
scenario "User can create an item" do | |
click_link "New Item" | |
fill_in "Name", with: item.name | |
fill_in "Description", with: item.description | |
attach_file "Image", File.expand_path("spec/fixtures/test.png") | |
binding.pry | |
click_button "Create Item" | |
page.should have_content item.name | |
end | |
end |
This file contains 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
1) Creating Items User can create an item | |
Failure/Error: click_button "Create Item" | |
Capybara::ElementNotFound: | |
Unable to find id 1 | |
# ./app/controllers/items_controller.rb:55:in `find_collection' | |
# ./spec/integration/item_create_spec.rb:22:in `block (2 levels) in <top (required)>' |
This file contains 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
def find_item | |
@item = Item.find(params[:id]) | |
end | |
def find_project | |
@project = Project.find(params[:project_id]) | |
end | |
def find_collection | |
ln55 @collection = Collection.find_by_id(@project.collection_id) | |
end | |
def create | |
@item = @project.items.build(params[:item]) | |
if @item.save | |
flash[:notice] = "Item added to #{@project.name}." | |
redirect_to [@collection, @project] | |
else | |
flash[:alert] = "Item failed to save to #{@project.name}." | |
render :new | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment