diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 51bc9d7..c4e5365 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -5,6 +5,12 @@ class ProjectsController < ApplicationController @project = Project.new end + # GET /projects + # GET /projects.json + def index + @projects = Project.all + end + # POST /projects # POST /projects.json def create @@ -12,7 +18,7 @@ class ProjectsController < ApplicationController respond_to do |format| if @project.save - format.html { redirect_to @project, notice: 'Project was successfully created.' } + format.html { redirect_to project_path(@project.id), notice: 'Project was successfully created.' } format.json { render action: 'show', status: :created, location: @project } else format.html { render action: 'new' } @@ -21,6 +27,12 @@ class ProjectsController < ApplicationController end end + # GET /project/1 + # GET /project/1.json + def show + set_project + end + private # Use callbacks to share common setup or constraints between actions. def set_project diff --git a/app/models/project.rb b/app/models/project.rb index e246c3a..16a7074 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -2,8 +2,7 @@ class Project < KalibroEntities::Entities::Project include ActiveModel::Validations include ActiveModel::Conversion extend ActiveModel::Naming - - attr_accessor :name + delegate :url_helpers, to: 'Rails.application.routes' def persisted? false diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb new file mode 100644 index 0000000..2aa2e72 --- /dev/null +++ b/app/views/projects/index.html.erb @@ -0,0 +1,25 @@ +

Listing Projects

+ + + + + + + + + + + + <% @projects.each do |project| %> + + + + + + <% end %> + +
NameDescription
<%= project.name %><%= project.description %><%= link_to 'Show', project_path(project.id) %><%=project.inspect%>
+ +
+ +<%= link_to 'New Project', new_project_path %> diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb new file mode 100644 index 0000000..d35d7fd --- /dev/null +++ b/app/views/projects/show.html.erb @@ -0,0 +1,11 @@ +

+ Name: + <%= @project.name %> +

+ +

+ Description: + <%= @project.description %> +

+ +<%= link_to 'Back', root_path %> diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 3c3e6c6..3a40b30 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -16,11 +16,12 @@ describe ProjectsController do context 'with a valid fields' do before :each do @subject = FactoryGirl.build(:project) - - Project.expects(:new).at_least_once.with(@subject.to_hash).returns(@subject) + @subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers + + Project.expects(:new).at_least_once.with(@subject_params).returns(@subject) Project.any_instance.expects(:save).returns(true) - post :create, :project => @subject.to_hash + post :create, :project => @subject_params end it 'should redirect to the show view' do @@ -35,14 +36,35 @@ describe ProjectsController do context 'with an invalid field' do before :each do @subject = FactoryGirl.build(:project) + @subject_params = Hash[FactoryGirl.attributes_for(:project).map { |k,v| [k.to_s, v.to_s] }] #FIXME: Mocha is creating the expectations with strings, but FactoryGirl returns everything with sybols and integers - Project.expects(:new).at_least_once.with(@subject.to_hash).returns(@subject) + Project.expects(:new).at_least_once.with(@subject_params).returns(@subject) Project.any_instance.expects(:save).returns(false) - post :create, :project => @subject.to_hash + post :create, :project => @subject_params end it { should render_template(:new) } end end + + describe 'show' do + before :each do + @subject = FactoryGirl.build(:project) + Project.expects(:find).with(@subject.id.to_s).returns(@subject) + get :show, :id => @subject.id + end + + it { should render_template(:show) } + end + + describe 'index' do + before :each do + @subject = FactoryGirl.build(:project) + Project.expects(:all).returns([@subject]) + get :index + end + + it { should render_template(:index) } + end end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 13be045..58aa7d8 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -2,5 +2,8 @@ FactoryGirl.define do factory :project do + id 1 + name "QT Calculator" + description "A simple calculator for us." end end -- libgit2 0.21.2