From a1ce779caed1fada783e0ea9b2b2c63025b9c0e6 Mon Sep 17 00:00:00 2001 From: Christopher Blanchard Date: Sun, 7 Jun 2015 00:26:09 +0100 Subject: [PATCH] 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