From 133902cf805e422ca1840b3f814a86d9c64acee9 Mon Sep 17 00:00:00 2001 From: Sebastian Schuster Date: Fri, 26 Apr 2013 16:08:24 +0200 Subject: [PATCH] Rewrote the view spec to use FactoryGirl and added scpecs for checking existence of clickable + buttons for stories with appropriate permissions --- spec/views/rb_taskboards/show_spec.rb | 79 +++++++++++++++++++-------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/spec/views/rb_taskboards/show_spec.rb b/spec/views/rb_taskboards/show_spec.rb index da3f64e52f..bb28d98183 100644 --- a/spec/views/rb_taskboards/show_spec.rb +++ b/spec/views/rb_taskboards/show_spec.rb @@ -1,13 +1,30 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe 'rb_taskboards/show' do - let(:project) { stub_model(Project) } - let(:sprint) { stub_model(Sprint) } - let(:statuses) { [stub_model(IssueStatus, :name => 'Open'), - stub_model(IssueStatus, :name => 'In Progress'), - stub_model(IssueStatus, :name => 'Closed')] } + let(:user1) { FactoryGirl.create(:user) } + let(:user2) { FactoryGirl.create(:user) } + let(:role_allowed) { FactoryGirl.create(:role, + :permissions => [:create_impediments, :create_tasks]) + } + let(:role_forbidden) { FactoryGirl.create(:role) } + #we need to create these as some view helpers access the database + let(:statuses) { [FactoryGirl.create(:issue_status), + FactoryGirl.create(:issue_status), + FactoryGirl.create(:issue_status)] } - let(:assignee) { stub_model(User, :firstname => 'Karl', :lastname => 'Gustav') } + let(:project) do + project = FactoryGirl.create(:project) + project.members = [FactoryGirl.create(:member, :principal => user1,:project => project,:roles => [role_allowed]), + FactoryGirl.create(:member, :principal => user2,:project => project,:roles => [role_forbidden])] + project + end + + let(:story_a) { FactoryGirl.build_stubbed(:story, :status => statuses[0])} + let(:story_b) { FactoryGirl.build_stubbed(:story, :status => statuses[1])} + let(:story_c) { FactoryGirl.build_stubbed(:story, :status => statuses[2])} + let(:stories) { [story_a, story_b, story_c] } + let(:sprint) { FactoryGirl.build_stubbed(:sprint) } + #let(:assignee) { user } before :each do view.extend RbCommonHelper @@ -16,27 +33,12 @@ describe 'rb_taskboards/show' do assign(:project, project) assign(:sprint, sprint) assign(:statuses, statuses) - assign(:all_issue_status, statuses) + + stories.each { |story| story.stub(:tasks).and_return([]) } + sprint.should_receive(:stories).with(project).and_return(stories) end describe 'story blocks' do - let(:story_a) { story = - stub_model(Story, :id => 1001, :subject => 'Story A', :status_id => statuses[0].id, :assigned_to => assignee) - story.status = statuses[0] - story } - let(:story_b) { story = stub_model(Story, :id => 1002, :subject => 'Story B', :status_id => statuses[1].id, :assigned_to => assignee) - story.status = statuses[1] - story } - let(:story_c) { story = stub_model(Story, :id => 1003, :subject => 'Story C', :status_id => statuses[2].id, :assigned_to => assignee) - story.status = statuses[2] - story } - let(:stories) { [story_a, story_b, story_c] } - - before do - stories.each { |story| story.stub(:tasks).and_return([]) } - - sprint.should_receive(:stories).with(project).and_return(stories) - end it 'contains the story id' do render @@ -78,4 +80,33 @@ describe 'rb_taskboards/show' do end end end + + describe 'create buttons' do + + it 'renders clickable + buttons with the right permissions' do + User.current = user1 + + render + + stories.each do |story| + assert_select "tr.story_#{story.id} td.add_new" do |td| + td.should have_content '+' + td.should have_css '.clickable' + end + end + end + + it 'does not render a clickable + buttons without the right permissions' do + User.current = user2 + + render + + stories.each do |story| + assert_select "tr.story_#{story.id} td.add_new" do |td| + td.should_not have_content '+' + td.should_not have_css '.clickable' + end + end + end + end end