def show; end
def create
+ if current_user.consider_pd
+ flash[:warning] = t(".already_declared")
+ else
+ current_user.consider_pd = params[:consider_pd]
+
+ if current_user.consider_pd
+ flash[:notice] = t(".successfully_declared") if current_user.save
+ else
+ flash[:warning] = t(".did_not_confirm")
+ end
+ end
+
redirect_to edit_account_path
end
end
consider_pd_why: "Why would I want my contributions to be Public Domain?"
consider_pd_why_url: https://osmfoundation.org/wiki/Licence_and_Legal_FAQ/Why_would_I_want_my_contributions_to_be_public_domain
confirm: Confirm
+ create:
+ successfully_declared: "You have successfully declared that you consider your edits to be in the Public Domain."
+ already_declared: "You have already declared that you consider your edits to be in the Public Domain."
+ did_not_confirm: "You didn't confirm that you consider your edits to be in the Public Domain."
browse:
deleted_ago_by_html: "Deleted %{time_ago} by %{user}"
edited_ago_by_html: "Edited %{time_ago} by %{user}"
assert_response :forbidden
end
- def test_create
+ def test_create_unconfirmed
user = create(:user)
session_for(user)
post account_pd_declaration_path
assert_redirected_to edit_account_path
+ assert_nil flash[:notice]
+ assert_equal "You didn't confirm that you consider your edits to be in the Public Domain.", flash[:warning]
+
+ user.reload
+ assert_not_predicate user, :consider_pd
+ end
+
+ def test_create_confirmed
+ user = create(:user)
+ session_for(user)
+
+ post account_pd_declaration_path, :params => { :consider_pd => true }
+
+ assert_equal "You have successfully declared that you consider your edits to be in the Public Domain.", flash[:notice]
+ assert_nil flash[:warning]
+
+ user.reload
+ assert_predicate user, :consider_pd
+ end
+
+ def test_create_already_declared_unconfirmed
+ user = create(:user, :consider_pd => true)
+ session_for(user)
+
+ post account_pd_declaration_path
+
+ assert_nil flash[:notice]
+ assert_equal "You have already declared that you consider your edits to be in the Public Domain.", flash[:warning]
+
+ user.reload
+ assert_predicate user, :consider_pd
+ end
+
+ def test_create_already_declared_confirmed
+ user = create(:user, :consider_pd => true)
+ session_for(user)
+
+ post account_pd_declaration_path, :params => { :consider_pd => true }
+
+ assert_nil flash[:notice]
+ assert_equal "You have already declared that you consider your edits to be in the Public Domain.", flash[:warning]
+
+ user.reload
+ assert_predicate user, :consider_pd
end
end
end
sign_in_as(@user)
end
- test "show checkbox if no declaration was made" do
+ test "can decline declaration if no declaration was made" do
visit account_pd_declaration_path
within_content_body do
assert_unchecked_field "I consider my contributions to be in the Public Domain"
assert_button "Confirm"
+
+ click_on "Confirm"
+
+ assert_no_text "You have also declared that you consider your edits to be in the Public Domain."
+ end
+ end
+
+ test "can confirm declaration if no declaration was made" do
+ visit account_pd_declaration_path
+
+ within_content_body do
+ assert_unchecked_field "I consider my contributions to be in the Public Domain"
+ assert_button "Confirm"
+
+ check "I consider my contributions to be in the Public Domain"
+ click_on "Confirm"
+
+ assert_text "You have also declared that you consider your edits to be in the Public Domain."
end
end