]> git.openstreetmap.org Git - rails.git/blob - test/models/issue_test.rb
Refactor users_controller to use CanCanCan for authorisation
[rails.git] / test / models / issue_test.rb
1 require "test_helper"
2
3 class IssueTest < ActiveSupport::TestCase
4   def test_assigned_role
5     issue = create(:issue)
6
7     assert issue.valid?
8     issue.assigned_role = "bogus"
9     assert_not issue.valid?
10   end
11
12   def test_reported_user
13     create(:language, :code => "en")
14     user = create(:user)
15     note = create(:note_comment, :author => create(:user)).note
16     anonymous_note = create(:note_comment, :author => nil).note
17     diary_entry = create(:diary_entry)
18     diary_comment = create(:diary_comment, :diary_entry => diary_entry)
19
20     issue = Issue.new(:reportable => user, :assigned_role => "administrator")
21     issue.save!
22     assert_equal issue.reported_user, user
23
24     issue = Issue.new(:reportable => note, :assigned_role => "administrator")
25     issue.save!
26     assert_equal issue.reported_user, note.author
27
28     issue = Issue.new(:reportable => anonymous_note, :assigned_role => "administrator")
29     issue.save!
30     assert_nil issue.reported_user
31
32     issue = Issue.new(:reportable => diary_entry, :assigned_role => "administrator")
33     issue.save!
34     assert_equal issue.reported_user, diary_entry.user
35
36     issue = Issue.new(:reportable => diary_comment, :assigned_role => "administrator")
37     issue.save!
38     assert_equal issue.reported_user, diary_comment.user
39   end
40 end