]> git.openstreetmap.org Git - rails.git/commitdiff
Merge branch 'master' into next
authorTom Hughes <tom@compton.nu>
Sun, 10 Jun 2018 16:02:12 +0000 (17:02 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 10 Jun 2018 16:02:12 +0000 (17:02 +0100)
19 files changed:
1  2 
.rubocop_todo.yml
Gemfile
Gemfile.lock
app/assets/stylesheets/common.scss
app/models/user.rb
app/views/browse/note.html.erb
app/views/diary_entry/_diary_comment.html.erb
app/views/diary_entry/_diary_entry.html.erb
app/views/layouts/_header.html.erb
app/views/user/view.html.erb
config/locales/en.yml
config/routes.rb
test/models/issue_test.rb
test/models/report_test.rb
test/system/issues_test.rb
test/system/report_diary_comment_test.rb
test/system/report_diary_entry_test.rb
test/system/report_note_test.rb
test/system/report_user_test.rb

index 5846de44f47d987a1bf16d6f67a19dd7227617e2,362cfcb3235123751c8018c9fb69250bff842c42..da801d681ab11b8071dcf50a836d3b884cb36ccd
@@@ -67,7 -67,7 +67,7 @@@ Metrics/AbcSize
  # Offense count: 41
  # Configuration parameters: CountComments, ExcludedMethods.
  Metrics/BlockLength:
-   Max: 250
 -  Max: 247
++  Max: 257
  
  # Offense count: 12
  # Configuration parameters: CountBlocks.
diff --cc Gemfile
Simple merge
diff --cc Gemfile.lock
Simple merge
Simple merge
Simple merge
Simple merge
index 8e17b095422a86c0681511c87fce68c97e5eaa14,8565ecc67e4c4053a7f3790883d0f0c91d3f4cce..4ac9a0f967f1950dbe6e86f98b8a9d2c1f7e5a42
@@@ -1,13 -1,10 +1,15 @@@
  <div class="clearfix diary-comment">
    <%= user_thumbnail diary_comment.user %>
-   <p class="deemphasize comment-heading" id="comment<%= diary_comment.id %>"><%= raw(t('diary_entry.diary_comment.comment_from', :link_user => (link_to h(diary_comment.user.display_name), user_path(diary_comment.user)), :comment_created_at => link_to(l(diary_comment.created_at, :format => :friendly), :anchor => "comment#{diary_comment.id}"))) %>
 -  <p class="deemphasize comment-heading" id="comment<%= diary_comment.id %>"><%= raw(t('.comment_from', :link_user => (link_to h(diary_comment.user.display_name), user_path(diary_comment.user)), :comment_created_at => link_to(l(diary_comment.created_at, :format => :friendly), :anchor => "comment#{diary_comment.id}"))) %></p>
++  <p class="deemphasize comment-heading" id="comment<%= diary_comment.id %>"><%= raw(t('.comment_from', :link_user => (link_to h(diary_comment.user.display_name), user_path(diary_comment.user)), :comment_created_at => link_to(l(diary_comment.created_at, :format => :friendly), :anchor => "comment#{diary_comment.id}"))) %>
 +    <% if current_user and diary_comment.user.id != current_user.id %>
 +      | <%= report_link(t(".report"), diary_comment) %>
 +    <% end %>
 +  </p>
 +
    <div class="richtext"><%= diary_comment.body.to_html %></div>
-   <%= if_administrator(:span) do %>
-     <%= link_to t('diary_entry.diary_comment.hide_link'), hide_diary_comment_path(:display_name => diary_comment.diary_entry.user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id), :method => :post, :data=> { :confirm => t('diary_entry.diary_comment.confirm') } %>
+   <% if current_user && current_user.administrator? %>
+     <span>
+       <%= link_to t('.hide_link'), hide_diary_comment_path(:display_name => diary_comment.diary_entry.user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id), :method => :post, :data=> { :confirm => t('.confirm') } %>
+     </span>
    <% end %>
  </div>
index ce311c168f5798ed3c464f558ccc6a2e2e5589dd,848221a2803ac6d0e6fcff71c18dead3ab696334..930f20e5ecd1e48dbe037889e44187c46c0ae97c
  
    <ul class='secondary-actions clearfix'>
      <% if params[:action] == 'list' %>
-       <li><%= link_to t('diary_entry.diary_entry.comment_link'), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'newcomment' %></li>
-       <li><%= link_to t('diary_entry.diary_entry.reply_link'), :controller => 'message', :action => 'new', :display_name => diary_entry.user.display_name, :title => "Re: #{diary_entry.title}" %></li>
-       <li><%= link_to t('diary_entry.diary_entry.comment_count', :count => diary_entry.visible_comments.count), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'comments' %></li>
+       <li><%= link_to t('.comment_link'), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'newcomment' %></li>
+       <li><%= link_to t('.reply_link'), new_message_path(diary_entry.user, :message => { :title => "Re: #{diary_entry.title}" }) %></li>
+       <li><%= link_to t('.comment_count', :count => diary_entry.visible_comments.count), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'comments' %></li>
      <% end %>
  
-     <%= if_user(diary_entry.user, :li) do %>
-       <%= link_to t('diary_entry.diary_entry.edit_link'), :action => 'edit', :display_name => diary_entry.user.display_name, :id => diary_entry.id %>
+     <% if current_user && current_user == diary_entry.user %>
+       <li><%= link_to t('.edit_link'), :action => 'edit', :display_name => diary_entry.user.display_name, :id => diary_entry.id %></li>
      <% end %>
  
-     <%= if_administrator(:li) do %>
-       <%= link_to t('diary_entry.diary_entry.hide_link'), hide_diary_entry_path(:display_name => diary_entry.user.display_name, :id => diary_entry.id), :method => :post, :data => { :confirm => t('diary_entry.diary_entry.confirm') } %>
 +    <% if current_user and diary_entry.user != current_user %>
 +      <li>
 +        <%= report_link(t(".report"), diary_entry) %>
 +      </li>
 +    <% end %>
 +
 -      <li><%= link_to t('.hide_link'), hide_diary_entry_path(:display_name => diary_entry.user.display_name, :id => diary_entry.id), :method => :post, :data => { :confirm => t('.confirm') } %></li>
+     <% if current_user && current_user.administrator? %>
++      <li>
++        <%= link_to t('.hide_link'), hide_diary_entry_path(:display_name => diary_entry.user.display_name, :id => diary_entry.id), :method => :post, :data => { :confirm => t('.confirm') } %>
++      </li>
      <% end %>
    </ul>
  </div>
Simple merge
index f797c4ba4e742ffb7bc406782ff38a427c44eeb0,3a09165b9d34ba8eafadfb0a5ddc96becc2352b4..0acb3f0145a622e05207d1bb109c18083064e503
              </li>
            <% end %>
  
-           <% if current_user and @this_user.id != current_user.id %>
++          <% if current_user and @user.id != current_user.id %>
 +            <li>
-               <%= report_link(t(".report"), @this_user) %>
++              <%= report_link(t(".report"), @user) %>
 +            </li>
 +          <% end %>
          </ul>
  
        <% end %>
Simple merge
Simple merge
index 8804b6b2861d79ed4be2d04c2ce545795d7a120f,0000000000000000000000000000000000000000..25721295302e28ebdb74e3e1e916ba9b7cc92a8b
mode 100644,000000..100644
--- /dev/null
@@@ -1,58 -1,0 +1,58 @@@
-     assert !issue.valid?
 +require "test_helper"
 +
 +class IssueTest < ActiveSupport::TestCase
 +  def test_assigned_role
 +    issue = create(:issue)
 +
 +    assert issue.valid?
 +    issue.assigned_role = "bogus"
++    assert_not issue.valid?
 +  end
 +
 +  def test_reported_user
 +    note = create(:note_comment, :author => create(:user)).note
 +    anonymous_note = create(:note_comment, :author => nil).note
 +    user = create(:user)
 +    create(:language, :code => "en")
 +    diary_entry = create(:diary_entry)
 +    issue = Issue.new
 +
 +    issue.reportable = user
 +    issue.save!
 +    assert_equal issue.reported_user, user
 +
 +    issue.reportable = note
 +    issue.save!
 +    assert_equal issue.reported_user, note.author
 +
 +    issue.reportable = anonymous_note
 +    issue.save!
 +    assert_nil issue.reported_user
 +
 +    issue.reportable = diary_entry
 +    issue.save!
 +    assert_equal issue.reported_user, diary_entry.user
 +  end
 +
 +  def test_default_assigned_role
 +    create(:language, :code => "en")
 +    diary_entry = create(:diary_entry)
 +    note = create(:note_with_comments)
 +
 +    issue = Issue.new
 +    issue.reportable = diary_entry
 +    issue.save!
 +    assert_equal "administrator", issue.assigned_role
 +
 +    issue = Issue.new
 +    issue.reportable = note
 +    issue.save!
 +    assert_equal "moderator", issue.assigned_role
 +
 +    # check the callback doesn't override an explicitly set role
 +    issue.assigned_role = "administrator"
 +    issue.save!
 +    issue.reload
 +    assert_equal "administrator", issue.assigned_role
 +  end
 +end
index 810035c9da5d9a3fbdd97d986ad189fb377c37b9,0000000000000000000000000000000000000000..b65753b822d4e1a075d5337d37d951457990a648
mode 100644,000000..100644
--- /dev/null
@@@ -1,35 -1,0 +1,35 @@@
-     assert !report.valid?
 +require "test_helper"
 +
 +class ReportTest < ActiveSupport::TestCase
 +  def test_issue_required
 +    report = create(:report)
 +
 +    assert report.valid?
 +    report.issue = nil
-     assert !report.valid?
++    assert_not report.valid?
 +  end
 +
 +  def test_user_required
 +    report = create(:report)
 +
 +    assert report.valid?
 +    report.user = nil
-     assert !report.valid?
++    assert_not report.valid?
 +  end
 +
 +  def test_details_required
 +    report = create(:report)
 +
 +    assert report.valid?
 +    report.details = ""
-     assert !report.valid?
++    assert_not report.valid?
 +  end
 +
 +  def test_category_required
 +    report = create(:report)
 +
 +    assert report.valid?
 +    report.category = ""
++    assert_not report.valid?
 +  end
 +end
index 5e60ee0f0c6f6b5448c43ee562cd5534b2fe7040,0000000000000000000000000000000000000000..b77908f076dbf2fbf5f0fe03ce121bb7e63b4175
mode 100644,000000..100644
--- /dev/null
@@@ -1,116 -1,0 +1,116 @@@
-     assert !page.has_content?(I18n.t("issues.index.issues_not_found"))
 +require "application_system_test_case"
 +
 +class IssuesTest < ApplicationSystemTestCase
 +  include IssuesHelper
 +
 +  def test_view_issues_not_logged_in
 +    visit issues_path
 +    assert page.has_content?(I18n.t("user.login.title"))
 +  end
 +
 +  def test_view_issues_normal_user
 +    sign_in_as(create(:user))
 +
 +    visit issues_path
 +    assert page.has_content?(I18n.t("application.require_moderator_or_admin.not_a_moderator_or_admin"))
 +  end
 +
 +  def test_view_no_issues
 +    sign_in_as(create(:moderator_user))
 +
 +    visit issues_path
 +    assert page.has_content?(I18n.t("issues.index.issues_not_found"))
 +  end
 +
 +  def test_view_issues
 +    sign_in_as(create(:moderator_user))
 +    issues = create_list(:issue, 3, :assigned_role => "moderator")
 +
 +    visit issues_path
 +    assert page.has_content?(issues.first.reported_user.display_name)
 +  end
 +
 +  def test_view_issues_with_no_reported_user
 +    sign_in_as(create(:moderator_user))
 +    anonymous_note = create(:note_with_comments)
 +    issue = create(:issue, :reportable => anonymous_note)
 +
 +    visit issues_path
 +    assert page.has_content?(reportable_title(anonymous_note))
 +
 +    visit issue_path(issue)
 +    assert page.has_content?(reportable_title(anonymous_note))
 +  end
 +
 +  def test_search_issues_by_user
 +    good_user = create(:user)
 +    bad_user = create(:user)
 +    create(:issue, :reportable => bad_user, :reported_user => bad_user, :assigned_role => "administrator")
 +
 +    sign_in_as(create(:administrator_user))
 +
 +    # No issues against the user
 +    visit issues_path
 +    fill_in "search_by_user", :with => good_user.display_name
 +    click_on "Search"
 +    assert page.has_content?(I18n.t("issues.index.issues_not_found"))
 +
 +    # User doesn't exist
 +    visit issues_path
 +    fill_in "search_by_user", :with => "Nonexistant User"
 +    click_on "Search"
 +    assert page.has_content?(I18n.t("issues.index.user_not_found"))
 +
 +    # Find Issue against bad_user
 +    visit issues_path
 +    fill_in "search_by_user", :with => bad_user.display_name
 +    click_on "Search"
++    assert_not page.has_content?(I18n.t("issues.index.issues_not_found"))
 +  end
 +
 +  def test_commenting
 +    issue = create(:issue)
 +    sign_in_as(create(:moderator_user))
 +
 +    visit issue_path(issue)
 +
 +    fill_in :issue_comment_body, :with => "test comment"
 +    click_on "Submit"
 +    assert page.has_content?(I18n.t("issue_comments.create.comment_created"))
 +    assert page.has_content?("test comment")
 +
 +    issue.reload
 +    assert_equal issue.comments.first.body, "test comment"
 +  end
 +
 +  def test_reassign_issue
 +    issue = create(:issue)
 +    assert_equal "administrator", issue.assigned_role
 +    sign_in_as(create(:administrator_user))
 +
 +    visit issue_path(issue)
 +
 +    fill_in :issue_comment_body, :with => "reassigning to moderators"
 +    check :reassign
 +    click_on "Submit"
 +
 +    issue.reload
 +    assert_equal "moderator", issue.assigned_role
 +  end
 +
 +  def test_issue_index_with_multiple_roles
 +    user1 = create(:user)
 +    user2 = create(:user)
 +    issue1 = create(:issue, :reportable => user1, :assigned_role => "administrator")
 +    issue2 = create(:issue, :reportable => user2, :assigned_role => "moderator")
 +
 +    user = create(:administrator_user)
 +    create(:user_role, :user => user, :role => "moderator")
 +    sign_in_as(user)
 +
 +    visit issues_path
 +
 +    assert page.has_link?(I18n.t("issues.index.reports_count", :count => issue1.reports_count), :href => issue_path(issue1))
 +    assert page.has_link?(I18n.t("issues.index.reports_count", :count => issue2.reports_count), :href => issue_path(issue2))
 +  end
 +end
index 05b76f695aeb6eaf230397b69567cf83b8d288f7,0000000000000000000000000000000000000000..852bcfa65d6d3a7fece6d822db7d8a8e571c6fd3
mode 100644,000000..100644
--- /dev/null
@@@ -1,35 -1,0 +1,35 @@@
-     assert !page.has_content?(I18n.t("diary_entry.diary_comment.report"))
 +require "application_system_test_case"
 +
 +class ReportDiaryCommentTest < ApplicationSystemTestCase
 +  def setup
 +    create(:language, :code => "en")
 +    @diary_entry = create(:diary_entry)
 +    @comment = create(:diary_comment, :diary_entry => @diary_entry)
 +  end
 +
 +  def test_no_link_when_not_logged_in
 +    visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
 +    assert page.has_content?(@comment.body)
 +
++    assert_not page.has_content?(I18n.t("diary_entry.diary_comment.report"))
 +  end
 +
 +  def test_it_works
 +    sign_in_as(create(:user))
 +    visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
 +    assert page.has_content? @diary_entry.title
 +
 +    click_on I18n.t("diary_entry.diary_comment.report")
 +    assert page.has_content? "Report"
 +    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
 +
 +    choose I18n.t("reports.new.categories.diary_comment.spam")
 +    fill_in "report_details", :with => "This comment is spam"
 +    click_on "Create Report"
 +
 +    assert page.has_content? "Your report has been registered sucessfully"
 +
 +    assert_equal 1, Issue.count
 +    assert Issue.last.reportable == @comment
 +  end
 +end
index 86d301e3c5edfca2a157e0f15a742bbdc0148fae,0000000000000000000000000000000000000000..15752777c5517f193afdcaee27a0d4fc3fa9e1d5
mode 100644,000000..100644
--- /dev/null
@@@ -1,58 -1,0 +1,58 @@@
-     assert !page.has_content?(I18n.t("diary_entry.diary_entry.report"))
 +require "application_system_test_case"
 +
 +class ReportDiaryEntryTest < ApplicationSystemTestCase
 +  def setup
 +    create(:language, :code => "en")
 +    @diary_entry = create(:diary_entry)
 +  end
 +
 +  def test_no_link_when_not_logged_in
 +    visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
 +    assert page.has_content?(@diary_entry.title)
 +
-     assert !issue.resolved?
++    assert_not page.has_content?(I18n.t("diary_entry.diary_entry.report"))
 +  end
 +
 +  def test_it_works
 +    sign_in_as(create(:user))
 +    visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
 +    assert page.has_content? @diary_entry.title
 +
 +    click_on I18n.t("diary_entry.diary_entry.report")
 +    assert page.has_content? "Report"
 +    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
 +
 +    choose I18n.t("reports.new.categories.diary_entry.spam")
 +    fill_in "report_details", :with => "This is advertising"
 +    click_on "Create Report"
 +
 +    assert page.has_content? "Your report has been registered sucessfully"
 +  end
 +
 +  def test_it_reopens_issue
 +    issue = create(:issue, :reportable => @diary_entry)
 +    issue.resolve!
 +
 +    sign_in_as(create(:user))
 +    visit diary_entry_path(@diary_entry.user.display_name, @diary_entry)
 +    assert page.has_content? @diary_entry.title
 +
 +    click_on I18n.t("diary_entry.diary_entry.report")
 +    assert page.has_content? "Report"
 +    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
 +
 +    choose I18n.t("reports.new.categories.diary_entry.spam")
 +    fill_in "report_details", :with => "This is advertising"
 +    click_on "Create Report"
 +
 +    issue.reload
++    assert_not issue.resolved?
 +    assert issue.open?
 +  end
 +
 +  def test_missing_report_params
 +    sign_in_as(create(:user))
 +    visit new_report_path
 +    assert page.has_content? I18n.t("reports.new.missing_params")
 +  end
 +end
index f885888349a709a3c3c63d968ecd7ddf87273e57,0000000000000000000000000000000000000000..759306e08f30dbc573782ece28576a3ab9d77f08
mode 100644,000000..100644
--- /dev/null
@@@ -1,49 -1,0 +1,49 @@@
-     assert !page.has_content?(I18n.t("browse.note.report"))
 +require "application_system_test_case"
 +
 +class ReportNoteTest < ApplicationSystemTestCase
 +  def test_no_link_when_not_logged_in
 +    note = create(:note_with_comments)
 +    visit browse_note_path(note)
 +    assert page.has_content?(note.comments.first.body)
 +
++    assert_not page.has_content?(I18n.t("browse.note.report"))
 +  end
 +
 +  def test_can_report_anonymous_notes
 +    note = create(:note_with_comments)
 +    sign_in_as(create(:user))
 +    visit browse_note_path(note)
 +
 +    click_on I18n.t("browse.note.report")
 +    assert page.has_content? "Report"
 +    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
 +
 +    choose I18n.t("reports.new.categories.note.spam")
 +    fill_in "report_details", :with => "This is spam"
 +    click_on "Create Report"
 +
 +    assert page.has_content? "Your report has been registered sucessfully"
 +
 +    assert_equal 1, Issue.count
 +    assert Issue.last.reportable == note
 +  end
 +
 +  def test_can_report_notes_with_author
 +    note = create(:note_comment, :author => create(:user)).note
 +    sign_in_as(create(:user))
 +    visit browse_note_path(note)
 +
 +    click_on I18n.t("browse.note.report")
 +    assert page.has_content? "Report"
 +    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
 +
 +    choose I18n.t("reports.new.categories.note.spam")
 +    fill_in "report_details", :with => "This is spam"
 +    click_on "Create Report"
 +
 +    assert page.has_content? "Your report has been registered sucessfully"
 +
 +    assert_equal 1, Issue.count
 +    assert Issue.last.reportable == note
 +  end
 +end
index 0331e3ad73a936d50c9dbf5690b0a4b81a20abea,0000000000000000000000000000000000000000..8bb7d9dd7ed397284faa97ee1952ebecfc0f6c68
mode 100644,000000..100644
--- /dev/null
@@@ -1,30 -1,0 +1,30 @@@
-     assert !page.has_content?(I18n.t("user.view.report"))
 +require "application_system_test_case"
 +
 +class ReportUserTest < ApplicationSystemTestCase
 +  def test_no_link_when_not_logged_in
 +    note = create(:note_with_comments)
 +    visit browse_note_path(note)
 +    assert page.has_content?(note.comments.first.body)
 +
++    assert_not page.has_content?(I18n.t("user.view.report"))
 +  end
 +
 +  def test_can_report_user
 +    user = create(:user)
 +    sign_in_as(create(:user))
 +    visit user_path(user.display_name)
 +
 +    click_on I18n.t("user.view.report")
 +    assert page.has_content? "Report"
 +    assert page.has_content? I18n.t("reports.new.disclaimer.intro")
 +
 +    choose I18n.t("reports.new.categories.user.vandal")
 +    fill_in "report_details", :with => "This user is a vandal"
 +    click_on "Create Report"
 +
 +    assert page.has_content? "Your report has been registered sucessfully"
 +
 +    assert_equal 1, Issue.count
 +    assert Issue.last.reportable == user
 +  end
 +end