Skip to content

Commit

Permalink
Hide email address of profiles by default
Browse files Browse the repository at this point in the history
We will run update_all for all existing profiles to set `hide_email`
to true.

Github issue tracker or gem help site are more appropriate means
for contacting owners. gem metadata can used to set link for these.
  • Loading branch information
sonalkr132 committed Mar 7, 2021
1 parent 49d5cb3 commit e39dfb8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
5 changes: 5 additions & 0 deletions db/migrate/20210307101812_change_users_hide_email_default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeUsersHideEmailDefault < ActiveRecord::Migration[6.1]
def change
change_column_default :users, :hide_email, from: nil, to: true
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_01_25_153619) do
ActiveRecord::Schema.define(version: 2021_03_07_101812) do

# These are extensions that must be enabled in order to support this database
enable_extension "hstore"
Expand Down Expand Up @@ -175,7 +175,7 @@
t.datetime "updated_at"
t.boolean "email_reset"
t.string "handle"
t.boolean "hide_email"
t.boolean "hide_email", default: true
t.string "twitter_username"
t.string "unconfirmed_email"
t.datetime "remember_token_expires_at"
Expand Down
8 changes: 2 additions & 6 deletions test/functional/api/v1/owners_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@ def self.should_respond_to(format)
assert_kind_of Array, response
end

should "return correct owner email" do
assert_equal @user.email, yield(@response.body)[0]["email"]
end

should "return correct owner handle" do
assert_equal @user.handle, yield(@response.body)[0]["handle"]
end

should "not return other owner email" do
assert yield(@response.body).map { |owner| owner["email"] }.exclude?(@other_user.email)
should "not return other owner handle" do
assert yield(@response.body).map { |owner| owner["handle"] }.exclude?(@other_user.handle)
end
end
end
Expand Down
15 changes: 8 additions & 7 deletions test/functional/api/v1/profiles_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,22 @@ def response_body
end

should respond_with :success
should "include the user email" do
assert response_body.key?("email")
assert_equal @user.email, response_body["email"]
should "hide the user email by default" do
refute response_body.key?("email")
end
end

context "on GET to show when hide email" do
context "on GET to show when hide email is disabled" do
setup do
@user.update(hide_email: true)
@user.update(hide_email: false)
get :show, params: { id: @user.handle }, format: format
end

should respond_with :success
should "hide the user email" do
refute response_body.key?("email")

should "include the user email" do
assert response_body.key?("email")
assert_equal @user.email, response_body["email"]
end

should "shows the handle" do
Expand Down
5 changes: 2 additions & 3 deletions test/functional/profiles_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class ProfilesControllerTest < ActionController::TestCase
setup { get :show, params: { id: @user.id } }

should respond_with :success
should "render Email link" do
assert page.has_content?("Email Me")
assert page.has_selector?("a[href='mailto:#{@user.email}']")
should "not render Email link by defaulr" do
refute page.has_selector?("a[href='mailto:#{@user.email}']")
end
end

Expand Down
17 changes: 8 additions & 9 deletions test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,21 @@ class UserTest < ActiveSupport::TestCase
assert_nil User.authenticate(@user.email, "bad")
end

should "have email and handle on JSON" do
should "have handle on JSON" do
json = JSON.parse(@user.to_json)
hash = { "id" => @user.id, "email" => @user.email, "handle" => @user.handle }
hash = { "id" => @user.id, "handle" => @user.handle }
assert_equal hash, json
end

should "have email and handle on XML" do
should "have handle on XML" do
xml = Nokogiri.parse(@user.to_xml)
assert_equal "user", xml.root.name
assert_equal %w[id handle email], xml.root.children.select(&:element?).map(&:name)
assert_equal @user.email, xml.at_css("email").content
assert_equal %w[id handle], xml.root.children.select(&:element?).map(&:name)
end

should "have email and handle on YAML" do
should "have handle on YAML" do
yaml = YAML.safe_load(@user.to_yaml)
hash = { "id" => @user.id, "email" => @user.email, "handle" => @user.handle }
hash = { "id" => @user.id, "handle" => @user.handle }
assert_equal hash, yaml
end

Expand All @@ -207,8 +206,8 @@ class UserTest < ActiveSupport::TestCase
assert_equal @user.handle, @user.name
end

should "setup a field to toggle showing email" do
assert_nil @user.hide_email
should "setup a field to toggle showing email with default true" do
assert @user.hide_email
end

should "only return rubygems" do
Expand Down

0 comments on commit e39dfb8

Please sign in to comment.