mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 21:10:54 +00:00
commit
0abb734aaa
5 changed files with 121 additions and 2 deletions
|
@ -15,6 +15,7 @@ class ShoutmsgsController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@shoutmsg = Shoutmsg.new params[:shoutmsg]
|
@shoutmsg = Shoutmsg.new params[:shoutmsg]
|
||||||
|
puts @shoutmsg
|
||||||
@shoutmsg.user = cuser
|
@shoutmsg.user = cuser
|
||||||
raise AccessError unless @shoutmsg.can_create? cuser
|
raise AccessError unless @shoutmsg.can_create? cuser
|
||||||
|
|
||||||
|
|
|
@ -99,8 +99,8 @@ class Issue < ActiveRecord::Base
|
||||||
cuser and !cuser.nil? and ((author == cuser) or cuser.admin?)
|
cuser and !cuser.nil? and ((author == cuser) or cuser.admin?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_create? cuser, params = {}
|
def can_create? cuser
|
||||||
Verification.contain params, [:title, :category_id, :text]
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_update? cuser
|
def can_update? cuser
|
||||||
|
|
8
spec/factories/issue.rb
Normal file
8
spec/factories/issue.rb
Normal file
|
@ -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
|
50
spec/features/issues/issues_spec.rb
Normal file
50
spec/features/issues/issues_spec.rb
Normal file
|
@ -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
|
60
spec/models/issue_spec.rb
Normal file
60
spec/models/issue_spec.rb
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
# == 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?' do
|
||||||
|
it "returns true" do
|
||||||
|
expect(issue.can_create? nil).to be_true
|
||||||
|
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
|
Loading…
Reference in a new issue