Commit cc9d5cd9c877c335912104f4be1ad53dca3202a7
Committed by
Rafael Manzo
1 parent
6c452183
Exists in
colab
and in
4 other branches
Showing and Listing projects
Showing
6 changed files
with
80 additions
and
8 deletions
Show diff stats
app/controllers/projects_controller.rb
| @@ -5,6 +5,12 @@ class ProjectsController < ApplicationController | @@ -5,6 +5,12 @@ class ProjectsController < ApplicationController | ||
| 5 | @project = Project.new | 5 | @project = Project.new |
| 6 | end | 6 | end |
| 7 | 7 | ||
| 8 | + # GET /projects | ||
| 9 | + # GET /projects.json | ||
| 10 | + def index | ||
| 11 | + @projects = Project.all | ||
| 12 | + end | ||
| 13 | + | ||
| 8 | # POST /projects | 14 | # POST /projects |
| 9 | # POST /projects.json | 15 | # POST /projects.json |
| 10 | def create | 16 | def create |
| @@ -12,7 +18,7 @@ class ProjectsController < ApplicationController | @@ -12,7 +18,7 @@ class ProjectsController < ApplicationController | ||
| 12 | 18 | ||
| 13 | respond_to do |format| | 19 | respond_to do |format| |
| 14 | if @project.save | 20 | if @project.save |
| 15 | - format.html { redirect_to @project, notice: 'Project was successfully created.' } | 21 | + format.html { redirect_to project_path(@project.id), notice: 'Project was successfully created.' } |
| 16 | format.json { render action: 'show', status: :created, location: @project } | 22 | format.json { render action: 'show', status: :created, location: @project } |
| 17 | else | 23 | else |
| 18 | format.html { render action: 'new' } | 24 | format.html { render action: 'new' } |
| @@ -21,6 +27,12 @@ class ProjectsController < ApplicationController | @@ -21,6 +27,12 @@ class ProjectsController < ApplicationController | ||
| 21 | end | 27 | end |
| 22 | end | 28 | end |
| 23 | 29 | ||
| 30 | + # GET /project/1 | ||
| 31 | + # GET /project/1.json | ||
| 32 | + def show | ||
| 33 | + set_project | ||
| 34 | + end | ||
| 35 | + | ||
| 24 | private | 36 | private |
| 25 | # Use callbacks to share common setup or constraints between actions. | 37 | # Use callbacks to share common setup or constraints between actions. |
| 26 | def set_project | 38 | def set_project |
app/models/project.rb
| @@ -2,8 +2,7 @@ class Project < KalibroEntities::Entities::Project | @@ -2,8 +2,7 @@ class Project < KalibroEntities::Entities::Project | ||
| 2 | include ActiveModel::Validations | 2 | include ActiveModel::Validations |
| 3 | include ActiveModel::Conversion | 3 | include ActiveModel::Conversion |
| 4 | extend ActiveModel::Naming | 4 | extend ActiveModel::Naming |
| 5 | - | ||
| 6 | - attr_accessor :name | 5 | + delegate :url_helpers, to: 'Rails.application.routes' |
| 7 | 6 | ||
| 8 | def persisted? | 7 | def persisted? |
| 9 | false | 8 | false |
| @@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
| 1 | +<h1>Listing Projects</h1> | ||
| 2 | + | ||
| 3 | +<table> | ||
| 4 | + <thead> | ||
| 5 | + <tr> | ||
| 6 | + <th>Name</th> | ||
| 7 | + <th>Description</th> | ||
| 8 | + <th></th> | ||
| 9 | + </tr> | ||
| 10 | + </thead> | ||
| 11 | + | ||
| 12 | + <tbody> | ||
| 13 | + <% @projects.each do |project| %> | ||
| 14 | + <tr> | ||
| 15 | + <td><%= project.name %></td> | ||
| 16 | + <td><%= project.description %></td> | ||
| 17 | + <td><%= link_to 'Show', project_path(project.id) %><%=project.inspect%></td> | ||
| 18 | + </tr> | ||
| 19 | + <% end %> | ||
| 20 | + </tbody> | ||
| 21 | +</table> | ||
| 22 | + | ||
| 23 | +<br> | ||
| 24 | + | ||
| 25 | +<%= link_to 'New Project', new_project_path %> |
spec/controllers/projects_controller_spec.rb
| @@ -16,11 +16,12 @@ describe ProjectsController do | @@ -16,11 +16,12 @@ describe ProjectsController do | ||
| 16 | context 'with a valid fields' do | 16 | context 'with a valid fields' do |
| 17 | before :each do | 17 | before :each do |
| 18 | @subject = FactoryGirl.build(:project) | 18 | @subject = FactoryGirl.build(:project) |
| 19 | - | ||
| 20 | - Project.expects(:new).at_least_once.with(@subject.to_hash).returns(@subject) | 19 | + @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 |
| 20 | + | ||
| 21 | + Project.expects(:new).at_least_once.with(@subject_params).returns(@subject) | ||
| 21 | Project.any_instance.expects(:save).returns(true) | 22 | Project.any_instance.expects(:save).returns(true) |
| 22 | 23 | ||
| 23 | - post :create, :project => @subject.to_hash | 24 | + post :create, :project => @subject_params |
| 24 | end | 25 | end |
| 25 | 26 | ||
| 26 | it 'should redirect to the show view' do | 27 | it 'should redirect to the show view' do |
| @@ -35,14 +36,35 @@ describe ProjectsController do | @@ -35,14 +36,35 @@ describe ProjectsController do | ||
| 35 | context 'with an invalid field' do | 36 | context 'with an invalid field' do |
| 36 | before :each do | 37 | before :each do |
| 37 | @subject = FactoryGirl.build(:project) | 38 | @subject = FactoryGirl.build(:project) |
| 39 | + @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 | ||
| 38 | 40 | ||
| 39 | - Project.expects(:new).at_least_once.with(@subject.to_hash).returns(@subject) | 41 | + Project.expects(:new).at_least_once.with(@subject_params).returns(@subject) |
| 40 | Project.any_instance.expects(:save).returns(false) | 42 | Project.any_instance.expects(:save).returns(false) |
| 41 | 43 | ||
| 42 | - post :create, :project => @subject.to_hash | 44 | + post :create, :project => @subject_params |
| 43 | end | 45 | end |
| 44 | 46 | ||
| 45 | it { should render_template(:new) } | 47 | it { should render_template(:new) } |
| 46 | end | 48 | end |
| 47 | end | 49 | end |
| 50 | + | ||
| 51 | + describe 'show' do | ||
| 52 | + before :each do | ||
| 53 | + @subject = FactoryGirl.build(:project) | ||
| 54 | + Project.expects(:find).with(@subject.id.to_s).returns(@subject) | ||
| 55 | + get :show, :id => @subject.id | ||
| 56 | + end | ||
| 57 | + | ||
| 58 | + it { should render_template(:show) } | ||
| 59 | + end | ||
| 60 | + | ||
| 61 | + describe 'index' do | ||
| 62 | + before :each do | ||
| 63 | + @subject = FactoryGirl.build(:project) | ||
| 64 | + Project.expects(:all).returns([@subject]) | ||
| 65 | + get :index | ||
| 66 | + end | ||
| 67 | + | ||
| 68 | + it { should render_template(:index) } | ||
| 69 | + end | ||
| 48 | end | 70 | end |