mardi 22 septembre 2015

rails testing rpsec capybara ActionController::ParameterMissing:param is missing or the value is empty: project

So i get this error:

     Failure/Error: click_link 'New Project'
         ActionController::ParameterMissing:
           param is missing or the value is empty: project
# ./app/controllers/projects_controller.rb:31:in `project_params'
     # ./app/controllers/projects_controller.rb:6:in `new'
     # ./spec/features/creating_projects_spec.rb:5:in `block (2 levels) in <top (required)>'

i have no idea why so maybe im missing something

Projects_controller.rb

class ProjectsController < ApplicationController
    def index
    end

    def new
        @project = Project.new(project_params)
        @project.save

    end

    def create
        @project = Project.new(project_params)

        if @project.save
            flash[:notice] = "Project has been created."
            redirect_to @project
        else
            flash[:alert] = "Project has not been created."

            render 'new'
        end
    end

    def show
        @project = Project.find(params[:id])
    endjava 8 release date

    private

    def project_params
    params.require(:project).permit(:name, :description)
    end
end

new.html.erb

<h2>Creating Projects</h2>
<%= form_for(@project) do |f| %>
<% if @project.errors.any? %>
<div id="error_explanation">
    <h2><%= pluralize(@project.errors.count, "error") %>
        Project has not been created.:</h2>

    <ul>
        <% @project.errors.full_message.each do |msg| %>
        <li><%= msg %></li>
        <% end %>
    </ul>
</div>
<% end %>
<p>
<%= f.label :name , "Name" %><br />
<%= f.text_field :name %>
</p>

<p>
    <%= f.label :description, "Description" %><br />
    <%= f.text_field :description %>
</p>
<%= f.submit %>
<% end %>

creating_projects_spec.rb

require 'spec_helper'
    feature 'Creating Projects' do
    before do
        visit '/'
        click_link 'New Project'
    end
        scenario "can create a project" do
        fill_in 'Name', with: 'TextMate 2'
        fill_in 'Description', with: 'A text-editor for OS X'
        click_button 'Create Project'
        expect(page).to have_content('Project has been created.')
        project = Project.where(name: "TextMate 2").first
        expect(page.current_url).to eql(project_url(project))
        title = "TextMate 2 - Projects - Ticketee"
        expect(page).to have_title(title)
    end
        scenario "can not create a project without a name" do
        click_button 'Create Project'
        expect(page).to have_content("Project has not been created.")
        expect(page).to have_content("Name can't be blank")
    end
end

This is my 2nd time doing the same thing,1st time i got through it but don't remember how and this time i'm stuck. :(

Aucun commentaire:

Enregistrer un commentaire