From 0518c916543d6e894f0b406153696b80b410c47d Mon Sep 17 00:00:00 2001 From: Christopher Blanchard Date: Sun, 7 Jun 2015 00:26:09 +0100 Subject: [PATCH 1/3] Added initial issue specs --- app/controllers/shoutmsgs_controller.rb | 1 + spec/models/issue_spec.rb | 63 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 spec/models/issue_spec.rb diff --git a/app/controllers/shoutmsgs_controller.rb b/app/controllers/shoutmsgs_controller.rb index 041116c..395328a 100644 --- a/app/controllers/shoutmsgs_controller.rb +++ b/app/controllers/shoutmsgs_controller.rb @@ -15,6 +15,7 @@ class ShoutmsgsController < ApplicationController def create @shoutmsg = Shoutmsg.new params[:shoutmsg] + puts @shoutmsg @shoutmsg.user = cuser raise AccessError unless @shoutmsg.can_create? cuser diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb new file mode 100644 index 0000000..5912530 --- /dev/null +++ b/spec/models/issue_spec.rb @@ -0,0 +1,63 @@ +# == Schema Information +# +# Table name: issues +# +# id :integer not null, primary key +# title :string(255) +# status :integer +# assigned_id :integer +# category_id :integer +# text :text +# author_id :integer +# created_at :datetime +# updated_at :datetime +# solution :text +# text_parsed :text +# + +require 'spec_helper' + +describe 'User' do + describe 'Permissions' do + let!(:user) { create :user } + let!(:admin) { create :user, :admin } + let(:issue) { Issue.new } + + describe 'can_show?' do + it 'returns true for author' do + issue.author = user + expect(issue.can_show? user).to be_true + end + it 'returns true for admin' do + expect(issue.can_show? admin).to be_true + end + it 'returns false if neither admin nor author' do + expect(issue.can_show? user).to be_false + end + end + describe 'can_create? is weird and broken' do + it "returns true if no params" do + expect(issue.can_create? user).to be_true + end + it 'returns false if no params' do + expect(issue.can_create? user, {foo: "bar"}).to be_false + end + end + describe 'can_update?' do + it 'returns true for admin' do + expect(issue.can_update? admin).to be_true + end + it 'returns false for non-admin' do + expect(issue.can_update? user).to be_false + end + end + describe 'can_destroy?' do + it 'returns true for admin' do + expect(issue.can_destroy? admin).to be_true + end + it 'returns false for non-admin' do + expect(issue.can_destroy? user).to be_false + end + end + end +end \ No newline at end of file From 5f0d09b5f18041e136e6d8024b03f8576b507c20 Mon Sep 17 00:00:00 2001 From: Christopher Blanchard Date: Sun, 7 Jun 2015 00:58:41 +0100 Subject: [PATCH 2/3] Added issue feature spec --- spec/factories/issue.rb | 8 +++++ spec/features/issues/issues_spec.rb | 50 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 spec/factories/issue.rb create mode 100644 spec/features/issues/issues_spec.rb diff --git a/spec/factories/issue.rb b/spec/factories/issue.rb new file mode 100644 index 0000000..f7a9d4d --- /dev/null +++ b/spec/factories/issue.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :issue do + sequence(:title) { |n| "Issue title #{n}" } + sequence(:text) { |n| "Issue Text #{n}" } + status Issue::STATUS_OPEN + association :author, factory: :user + end +end \ No newline at end of file diff --git a/spec/features/issues/issues_spec.rb b/spec/features/issues/issues_spec.rb new file mode 100644 index 0000000..2b01efc --- /dev/null +++ b/spec/features/issues/issues_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +feature 'Issues' do + let!(:user) { create :user } + + scenario 'creation' do + sign_in_as user + click_link 'Agenda' + click_link 'Issues' + click_link 'New issue' + expect(page).to have_content('New Issue') + issue_title = 'My Problem' + issue_description = "There's a fly in my soup" + fill_in 'Title', with: issue_title + fill_in 'Text', with: issue_description + click_button 'Submit' + expect(page).to have_content('Issue was successfully created.') + expect(page).to have_content(issue_title) + expect(page).to have_content(issue_description) + end + + feature 'adminstration' do + let!(:admin) { create :user, :admin } + let!(:issue) { create :issue, author: user } + + scenario 'issue management' do + sign_in_as admin + click_link 'Admin' + click_link 'Issues (1)' + within '#open' do + expect(page).to have_content(issue.title) + expect(page).to have_content(issue.author.username) + end + visit edit_issue_path(issue) + expect(page).to have_content('Editing Issue') + solution = "Use a baseball bat" + fill_in "Title", with: "Foo" + fill_in "Text", with: "Bar" + fill_in "Solution", with: solution + select 'Solved', from: 'Status' + click_button 'Submit' + expect(page).to have_content('Issue was successfully updated.') + visit issues_path + within '#solved' do + expect(page).to have_content("Foo") + expect(page).to have_content(issue.author.username) + end + end + end +end \ No newline at end of file From 24eb454f1180876de9718fc55c62f39b44bc126b Mon Sep 17 00:00:00 2001 From: Christopher Blanchard Date: Sun, 7 Jun 2015 10:20:23 +0100 Subject: [PATCH 3/3] Fix for can_create? weirdness --- app/models/issue.rb | 4 ++-- spec/models/issue_spec.rb | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index f31f870..594ddb0 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -99,8 +99,8 @@ class Issue < ActiveRecord::Base cuser and !cuser.nil? and ((author == cuser) or cuser.admin?) end - def can_create? cuser, params = {} - Verification.contain params, [:title, :category_id, :text] + def can_create? cuser + true end def can_update? cuser diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 5912530..dc5f961 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -35,12 +35,9 @@ describe 'User' do expect(issue.can_show? user).to be_false end end - describe 'can_create? is weird and broken' do - it "returns true if no params" do - expect(issue.can_create? user).to be_true - end - it 'returns false if no params' do - expect(issue.can_create? user, {foo: "bar"}).to be_false + describe 'can_create?' do + it "returns true" do + expect(issue.can_create? nil).to be_true end end describe 'can_update?' do