From 3477ee7fcd9cfff4b911781b2078f3656b34ba3d Mon Sep 17 00:00:00 2001 From: Jeffrey Warren Date: Wed, 2 Nov 2016 13:17:19 -0400 Subject: [PATCH] various tests and fixes #753, fixes #947, fixes #946 (#948) --- README.md | 2 +- app/models/drupal_node_community_tag.rb | 2 +- app/views/map/show.html.erb | 2 +- app/views/tag/show.html.erb | 2 +- app/views/users/profile.html.erb | 2 +- test/fixtures/users.yml | 6 ++++++ test/functional/map_controller_test.rb | 1 + test/functional/users_controller_test.rb | 5 +++++ test/unit/drupal_tag_test.rb | 10 ++++++++++ test/unit/drupal_user_test.rb | 7 +++++++ 10 files changed, 34 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b8bf2d5fbe..d3c7169756 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Some key features include: ## Contributing -We welcome contributions, and are especially interested in welcoming [first time contributors](#first-time). Read more about [how to contribute](#developers) below! +We welcome contributions, and are especially interested in welcoming [first time contributors](#first-time). Read more about [how to contribute](#developers) below! We especially welcome contributions from people from groups underrepresented in free and open source software! ### Code of Conduct diff --git a/app/models/drupal_node_community_tag.rb b/app/models/drupal_node_community_tag.rb index 30405d51e7..01577cdaba 100644 --- a/app/models/drupal_node_community_tag.rb +++ b/app/models/drupal_node_community_tag.rb @@ -29,7 +29,7 @@ def author end def user - DrupalUsers.find(self.uid).user + DrupalUsers.find_by_uid(self.uid).try(:user) end def drupal_user diff --git a/app/views/map/show.html.erb b/app/views/map/show.html.erb index 5f19c68818..96164c238d 100644 --- a/app/views/map/show.html.erb +++ b/app/views/map/show.html.erb @@ -57,7 +57,7 @@
- <% unless @node.map.notes.empty? %> + <% unless @node.map.notes.nil? %>

Notes

<%= raw RDiscount.new(auto_link(@node.map.notes, :sanitize => false)).to_html %>

diff --git a/app/views/tag/show.html.erb b/app/views/tag/show.html.erb index 0a3203e3ca..8b958ff5d0 100644 --- a/app/views/tag/show.html.erb +++ b/app/views/tag/show.html.erb @@ -63,7 +63,7 @@ class="active"<% end %>> <%= t('tag.show.questions') %> class="active"<% end %>> <%= raw t('tag.show.wiki_pages') %> class="active"<% end %>> <%= t('tag.show.maps') %> - class="active"<% end %>>
  • <%= raw t('tag.show.contributors') %>
  • + class="active"<% end %>> <%= raw t('tag.show.contributors') %>
    diff --git a/app/views/users/profile.html.erb b/app/views/users/profile.html.erb index 11105aff18..2a57d1c4a0 100644 --- a/app/views/users/profile.html.erb +++ b/app/views/users/profile.html.erb @@ -156,7 +156,7 @@
  • (<%= @user.like_count %>)
  • -
  • (<%= @user.user.barnstars.length %>)
  • +
  • (<%= @user.user.try(:barnstars).try(:length) %>)

  • diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index da2d703ae3..ae9a188479 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -57,3 +57,9 @@ test_user: name: testuser status: 1 mail: testuser@publiclab.org + +legacy_user: + uid: 11 + name: legacy + status: 1 + mail: legacy@publiclab.org diff --git a/test/functional/map_controller_test.rb b/test/functional/map_controller_test.rb index 12f41707d1..2745880c79 100644 --- a/test/functional/map_controller_test.rb +++ b/test/functional/map_controller_test.rb @@ -26,4 +26,5 @@ class MapControllerTest < ActionController::TestCase date: map.created_at.strftime("%m-%d-%Y") assert_response :success end + end diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 35f8522f6b..b33881d539 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -260,4 +260,9 @@ def setup assert_not_nil assigns(:comments) assert_template partial: 'comments/_comments' end + + test "profiles for legacy users" do + user = users(:legacy_user) + assert_response :success + end end diff --git a/test/unit/drupal_tag_test.rb b/test/unit/drupal_tag_test.rb index c52e2070c8..8d1a68d464 100644 --- a/test/unit/drupal_tag_test.rb +++ b/test/unit/drupal_tag_test.rb @@ -26,6 +26,16 @@ class DrupalTagTest < ActiveSupport::TestCase assert (subscribers.to_a.collect(&:last).map { |o| o[:user]}).include?(tag_selection(:awesome).user) end + test "creating a tag with a bad uid" do + community_tag = DrupalNodeCommunityTag.new({ + uid: 1343151513, + tid: tags(:awesome).tid, + nid: node(:one).nid + }) + assert community_tag.save! + assert_nil community_tag.author + end + test "tag weekly tallies" do tag = tags(:awesome) tallies = tag.weekly_tallies diff --git a/test/unit/drupal_user_test.rb b/test/unit/drupal_user_test.rb index 41591353d1..887b87148b 100644 --- a/test/unit/drupal_user_test.rb +++ b/test/unit/drupal_user_test.rb @@ -34,4 +34,11 @@ class DrupalUserTest < ActiveSupport::TestCase assert users(:lurker).first_time_poster end + test "user.barnstars" do + user = users(:bob) + assert_equal 0, user.user.barnstars.length + user = users(:legacy_user) + assert_nil user.user + end + end