ensl.org/spec/models/issue_spec.rb

69 lines
1.5 KiB
Ruby
Raw Normal View History

2015-06-06 23:26:09 +00:00
# == 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
#
2019-10-17 18:29:15 +00:00
require "rails_helper"
require 'pry'
2015-06-06 23:26:09 +00:00
2015-08-15 18:23:42 +00:00
describe "User" do
describe "Permissions" do
let!(:user) { create :user }
let!(:admin) { create :user, :admin }
let(:issue) { Issue.new }
2015-08-15 18:23:42 +00:00
describe "can_show?" do
it "returns true for author" do
issue.author = user
expect(issue.can_show? user).to be_truthy
end
2015-08-15 18:23:42 +00:00
it "returns true for admin" do
expect(issue.can_show? admin).to be_truthy
end
2015-08-15 18:23:42 +00:00
it "returns false if neither admin nor author" do
expect(issue.can_show? user).to be_falsey
end
end
2015-08-15 18:23:42 +00:00
describe "can_create?" do
it "returns true" do
expect(issue.can_create? nil).to be_truthy
end
end
2015-08-15 18:23:42 +00:00
describe "can_update?" do
it "returns true for admin" do
expect(issue.can_update? admin).to be_truthy
end
2015-08-15 18:23:42 +00:00
it "returns false for non-admin" do
expect(issue.can_update? user).to be_falsey
end
end
2015-08-15 18:23:42 +00:00
describe "can_destroy?" do
it "returns true for admin" do
expect(issue.can_destroy? admin).to be_truthy
end
2015-08-15 18:23:42 +00:00
it "returns false for non-admin" do
expect(issue.can_destroy? user).to be_falsey
end
end
end
end