]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5521'
authorTom Hughes <tom@compton.nu>
Sat, 15 Feb 2025 14:44:58 +0000 (14:44 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 15 Feb 2025 14:44:58 +0000 (14:44 +0000)
18 files changed:
app/abilities/ability.rb
app/assets/javascripts/application.js
app/assets/stylesheets/common.scss
app/controllers/accounts/pd_declarations_controller.rb [new file with mode: 0644]
app/controllers/accounts/terms_controller.rb
app/controllers/users_controller.rb
app/helpers/application_helper.rb
app/views/accounts/edit.html.erb
app/views/accounts/pd_declarations/show.html.erb [new file with mode: 0644]
app/views/accounts/terms/show.html.erb
app/views/layouts/_header.html.erb
app/views/users/new.html.erb
config/locales/en.yml
config/routes.rb
test/controllers/accounts/pd_declarations_controller_test.rb [new file with mode: 0644]
test/controllers/accounts/terms_controller_test.rb
test/integration/user_creation_test.rb
test/system/account_pd_declaration_test.rb [new file with mode: 0644]

index 3116bc5cdd451501ccbaebe66d3034f0178c2887..adedce543e0f889ec519e07a378b26e40bd80a15 100644 (file)
@@ -29,7 +29,7 @@ class Ability
 
     if user&.active?
       can :welcome, :site
-      can :read, [:deletion, :account_terms]
+      can :read, [:deletion, :account_terms, :account_pd_declaration]
 
       if Settings.status != "database_offline"
         can [:read, :create, :destroy], :changeset_subscription
@@ -38,6 +38,7 @@ class Ability
         can [:read, :create, :destroy], :oauth2_authorization
         can [:update, :destroy], :account
         can :update, :account_terms
+        can :create, :account_pd_declaration
         can :read, :dashboard
         can [:create, :subscribe, :unsubscribe], DiaryEntry
         can :update, DiaryEntry, :user => user
index 2e13f69671bec7253adbe5c98887a33c105d7725..464bbecee17db7f7ded5ddcf115ff0dc2c13395b 100644 (file)
@@ -90,21 +90,76 @@ $(document).ready(function () {
   // See https://turbo.hotwired.dev/reference/drive#turbo.session.drive
   Turbo.session.drive = false;
 
-  var headerWidth = 0,
-      compactWidth = 0;
+  const $expandedSecondaryMenu = $("header nav.secondary > ul"),
+        $collapsedSecondaryMenu = $("#compact-secondary-nav > ul"),
+        secondaryMenuItems = [],
+        breakpointWidth = 768;
+  let moreItemWidth = 0;
 
   function updateHeader() {
     var windowWidth = $(window).width();
 
-    if (windowWidth < compactWidth) {
-      $("body").removeClass("compact-nav").addClass("small-nav");
-    } else if (windowWidth < headerWidth) {
-      $("body").addClass("compact-nav").removeClass("small-nav");
+    if (windowWidth < breakpointWidth) {
+      $("body").addClass("small-nav");
+      expandAllSecondaryMenuItems();
     } else {
-      $("body").removeClass("compact-nav").removeClass("small-nav");
+      $("body").removeClass("small-nav");
+      const availableWidth = $expandedSecondaryMenu.width();
+      secondaryMenuItems.forEach(function (item) {
+        $(item[0]).remove();
+      });
+      let runningWidth = 0,
+          i = 0,
+          requiredWidth;
+      for (; i < secondaryMenuItems.length; i++) {
+        runningWidth += secondaryMenuItems[i][1];
+        if (i < secondaryMenuItems.length - 1) {
+          requiredWidth = runningWidth + moreItemWidth;
+        } else {
+          requiredWidth = runningWidth;
+        }
+        if (requiredWidth > availableWidth) {
+          break;
+        }
+        expandSecondaryMenuItem($(secondaryMenuItems[i][0]));
+      }
+      for (; i < secondaryMenuItems.length; i++) {
+        collapseSecondaryMenuItem($(secondaryMenuItems[i][0]));
+      }
     }
   }
 
+  function expandAllSecondaryMenuItems() {
+    secondaryMenuItems.forEach(function (item) {
+      expandSecondaryMenuItem($(item[0]));
+    });
+  }
+
+  function expandSecondaryMenuItem($item) {
+    $item.children("a")
+      .removeClass("dropdown-item")
+      .addClass("nav-link")
+      .addClass(function () {
+        return $(this).hasClass("active") ? "text-secondary-emphasis" : "text-secondary";
+      });
+    $item.addClass("nav-item").insertBefore("#compact-secondary-nav");
+    toggleCompactSecondaryNav();
+  }
+
+  function collapseSecondaryMenuItem($item) {
+    $item.children("a")
+      .addClass("dropdown-item")
+      .removeClass("nav-link text-secondary text-secondary-emphasis");
+    $item.removeClass("nav-item").appendTo($collapsedSecondaryMenu);
+    toggleCompactSecondaryNav();
+  }
+
+  function toggleCompactSecondaryNav() {
+    $("#compact-secondary-nav").toggle(
+      $collapsedSecondaryMenu.find("li").length > 0
+    );
+  }
+
   /*
    * Chrome 60 and later seem to fire the "ready" callback
    * before the DOM is fully ready causing us to measure the
@@ -112,20 +167,10 @@ $(document).ready(function () {
    * to defer the measurement slightly as a workaround.
    */
   setTimeout(function () {
-    $("header").children(":visible").each(function (i, e) {
-      headerWidth += $(e).outerWidth();
+    $expandedSecondaryMenu.find("li:not(#compact-secondary-nav)").each(function () {
+      secondaryMenuItems.push([this, $(this).width()]);
     });
-
-    $("body").addClass("compact-nav");
-
-    $("header").children(":visible").each(function (i, e) {
-      compactWidth += $(e).outerWidth();
-    });
-
-    $("body").removeClass("compact-nav");
-
-    $("header").removeClass("text-nowrap");
-    $("header nav.secondary > ul").removeClass("flex-nowrap");
+    moreItemWidth = $("#compact-secondary-nav").width();
 
     updateHeader();
 
index fc9af9803e53cbcdb340680b11ba95e9be3769e4..a27976854f99dc90af33a7878e326ccdff9413f8 100644 (file)
@@ -131,10 +131,6 @@ header {
     font-size: 14px;
   }
 
-  nav.primary {
-    margin-right: auto;
-  }
-
   .username {
     max-width: 12em;
   }
@@ -174,7 +170,11 @@ nav.primary {
 
 nav.secondary {
   .nav-link {
-    padding: 0.3rem;
+    padding: 0 0.3rem;
+  }
+
+  > ul {
+    height: 1.5em;
   }
 }
 
@@ -191,15 +191,6 @@ nav.primary, nav.secondary {
   display: none;
 }
 
-body.compact-nav {
-  #compact-secondary-nav {
-    display: inline-block;
-  }
-  .compact-hide {
-    display: none;
-  }
-}
-
 body.small-nav {
   #menu-icon {
     display: block;
@@ -240,6 +231,10 @@ body.small-nav {
   nav.secondary {
     flex-direction: column;
 
+    > ul {
+      height: auto;
+    }
+
     .user-menu, .login-menu {
       width: 100%;
     }
diff --git a/app/controllers/accounts/pd_declarations_controller.rb b/app/controllers/accounts/pd_declarations_controller.rb
new file mode 100644 (file)
index 0000000..2d2569d
--- /dev/null
@@ -0,0 +1,28 @@
+module Accounts
+  class PdDeclarationsController < ApplicationController
+    layout "site"
+
+    before_action :authorize_web
+    before_action :set_locale
+
+    authorize_resource :class => :account_pd_declaration
+
+    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
+end
index 13e9de890925c4704d93b71b4701fcf52f144c72..03007a5323f6788152d37eeb43eff5aa40a9dde0 100644 (file)
@@ -33,7 +33,6 @@ module Accounts
         flash[:notice] = { :partial => "accounts/terms/terms_declined_flash" } if current_user.save
       else
         unless current_user.terms_agreed?
-          current_user.consider_pd = params[:user][:consider_pd]
           current_user.tou_agreed = Time.now.utc
           current_user.terms_agreed = Time.now.utc
           current_user.terms_seen = true
index a0be87bdc11fa6417601b6e278030fc673825515..0df971bd4f39dd55d2f1eba2307143a41f2aae5a 100644 (file)
@@ -222,8 +222,7 @@ class UsersController < ApplicationController
   def user_params
     params.require(:user).permit(:email, :display_name,
                                  :auth_provider, :auth_uid,
-                                 :pass_crypt, :pass_crypt_confirmation,
-                                 :consider_pd)
+                                 :pass_crypt, :pass_crypt_confirmation)
   end
 
   ##
index ff6dcd2ff194820556e8a85382f97677ddd97d30..86a3d56cdb96c2df8d8cf6c45e71a839c5a165c6 100644 (file)
@@ -43,7 +43,7 @@ module ApplicationHelper
   end
 
   def header_nav_link_class(path)
-    ["nav-link", current_page?(path) ? "text-secondary-emphasis" : "text-secondary"]
+    ["nav-link", current_page?(path) ? "active text-secondary-emphasis" : "text-secondary"]
   end
 
   def application_data
index 7a10b12e3d281c181248d9bd5b11312eea62c7b0..ce7dd97a83d4dd7597810559c4d2fa8452f2b56b 100644 (file)
     <small class="form-text text-body-secondary">(<a href="<%= t ".openid.link" %>" target="_new"><%= t ".openid.link text" %></a>)</small>
   </fieldset>
 
-  <div class="mb-3">
-    <label class="form-label"><%= t ".contributor terms.heading" %></label>
+  <div class="mb-3 d-flex flex-column flex-sm-row column-gap-1">
+    <label class="form-label text-nowrap mb-0"><%= t ".contributor terms.heading" %></label>
     <span class="form-text text-body-secondary">
       <% if current_user.terms_agreed? %>
         <%= t ".contributor terms.agreed" %>
         (<a href="<%= t ".contributor terms.link" %>" target="_new"><%= t ".contributor terms.link text" %></a>)
+        <br>
         <% if current_user.consider_pd? %>
           <%= t ".contributor terms.agreed_with_pd" %>
+        <% else %>
+          <%= t ".contributor terms.not_agreed_with_pd" %>
+          (<%= link_to t(".contributor terms.pd_link_text"), account_pd_declaration_path %>)
         <% end %>
       <% else %>
         <%= t ".contributor terms.not yet agreed" %>
diff --git a/app/views/accounts/pd_declarations/show.html.erb b/app/views/accounts/pd_declarations/show.html.erb
new file mode 100644 (file)
index 0000000..ad314fe
--- /dev/null
@@ -0,0 +1,14 @@
+<% content_for :heading do %>
+  <h1><%= t ".title" %></h1>
+<% end %>
+
+<%= bootstrap_form_tag do |f| %>
+  <%= f.form_group :help => link_to(t(".consider_pd_why"), t(".consider_pd_why_url"), :target => :new) do %>
+    <%= f.check_box :consider_pd,
+                    :label => t(".consider_pd"),
+                    :autocomplete => :off,
+                    :checked => current_user.consider_pd,
+                    :disabled => current_user.consider_pd %>
+  <% end %>
+  <%= f.primary t(".confirm"), :disabled => current_user.consider_pd %>
+<% end %>
index 3cc52302ff8a3d537d958e4ecf65ea5ecc19a6d6..c1c0e0a89a77760da67d05d65de7ade49d9074c7 100644 (file)
     <%= submit_tag(t(".continue"), :name => "continue", :id => "continue", :disabled => true, :class => "btn btn-primary") %>
     <%= submit_tag(t(".cancel"), :name => "decline", :id => "decline", :class => "btn btn-outline-secondary") %>
   </div>
-
-  <div class="mb-3">
-    <div class="form-check">
-      <%= check_box("user", "consider_pd", :class => "form-check-input") %>
-    <label for="user_consider_pd" class="form-check-label">
-      <%= t ".consider_pd" %>
-    </label>
-    <span class="minorNote">(<%= link_to(t(".consider_pd_why"), t(".consider_pd_why_url"), :target => :new) %>)</span>
-  </div>
 <% end %>
index 45e23fc2b914471be7f4f40a830ef341447c2ef6..aa524938181c32cdb210fdb1c1cb9168b056b58d 100644 (file)
       </ul>
     </div>
   </nav>
-  <nav class='secondary d-flex gap-2 align-items-center'>
-    <ul class='nav flex-nowrap'>
+  <nav class='secondary d-flex gap-2 flex-grow-1 align-items-center'>
+    <ul id='secondary-nav-menu' class='nav flex-grow-1' data-turbo-permanent>
       <% if Settings.status != "database_offline" && can?(:index, Issue) %>
-        <li class="compact-hide nav-item">
+        <li class="nav-item">
           <%= link_to issues_path(:status => "open"), :class => header_nav_link_class(issues_path) do %>
             <%= t("layouts.issues") %>
             <%= open_issues_count %>
           <% end -%>
         </li>
       <% end %>
-      <li class="compact-hide nav-item">
+      <li class="nav-item">
         <%= link_to t("layouts.history"), history_path, :class => header_nav_link_class(history_path) %>
       </li>
-      <li class="compact-hide nav-item">
+      <li class="nav-item">
         <%= link_to t("layouts.export"), export_path, :class => header_nav_link_class(export_path) %>
       </li>
-      <li class="compact-hide nav-item">
+      <li class="nav-item">
         <%= link_to t("layouts.gps_traces"), traces_path, :class => header_nav_link_class(traces_path) %>
       </li>
-      <li class="compact-hide nav-item">
+      <li class="nav-item">
         <%= link_to t("layouts.user_diaries"), diary_entries_path, :class => header_nav_link_class(diary_entries_path) %>
       </li>
-      <li class="compact-hide nav-item">
+      <li class="nav-item">
         <%= link_to t("layouts.communities"), communities_path, :class => header_nav_link_class(communities_path) %>
       </li>
-      <li class="compact-hide nav-item">
+      <li class="nav-item">
         <%= link_to t("layouts.copyright"), copyright_path, :class => header_nav_link_class(copyright_path) %>
       </li>
-      <li class="compact-hide nav-item">
+      <li class="nav-item">
         <%= link_to t("layouts.help"), help_path, :class => header_nav_link_class(help_path) %>
       </li>
-      <li class="compact-hide nav-item">
+      <li class="nav-item">
         <%= link_to t("layouts.about"), about_path, :class => header_nav_link_class(about_path) %>
       </li>
-      <li id="compact-secondary-nav" class="dropdown nav-item">
+      <li id="compact-secondary-nav" class="dropdown nav-item ms-auto">
         <button class="dropdown-toggle nav-link btn btn-outline-secondary border-0 bg-body text-secondary" type="button" data-bs-toggle="dropdown"><%= t "layouts.more" %></button>
         <ul class="dropdown-menu">
-          <% if Settings.status != "database_offline" && can?(:index, Issue) %>
-            <li>
-              <%= link_to issues_path(:status => "open"), :class => "dropdown-item" do %>
-                <%= t("layouts.issues") %>
-                <%= open_issues_count %>
-              <% end -%>
-            </li>
-          <% end %>
-          <li><%= link_to t("layouts.history"), history_path, :class => "dropdown-item" %></li>
-          <li><%= link_to t("layouts.export"), export_path, :class => "dropdown-item" %></li>
-          <li><%= link_to t("layouts.gps_traces"), traces_path, :class => "dropdown-item" %></li>
-          <li><%= link_to t("layouts.user_diaries"), diary_entries_path, :class => "dropdown-item" %></li>
-          <li><%= link_to t("layouts.communities"), communities_path, :class => "dropdown-item" %></li>
-          <li><%= link_to t("layouts.copyright"), copyright_path, :class => "dropdown-item" %></li>
-          <li><%= link_to t("layouts.help"), help_path, :class => "dropdown-item" %></li>
-          <li><%= link_to t("layouts.about"), about_path, :class => "dropdown-item" %></li>
         </ul>
       </li>
     </ul>
index 37493418ab0836814c9e3ea0aa38d7c805a1b5a5..22db279d9ebe6723580dbe9817511d068573292b 100644 (file)
                                                  :contributor_terms_link => link_to(t(".by_signing_up.contributor_terms"),
                                                                                     t(".by_signing_up.contributor_terms_url"),
                                                                                     :target => :new)) %></p>
-  <%= f.form_group do %>
-    <%= f.check_box :consider_pd,
-                    :tabindex => 5,
-                    :label => t(".consider_pd_html",
-                                :consider_pd_link => link_to(t(".consider_pd"),
-                                                             t(".consider_pd_url"),
-                                                             :target => :new)) %>
-  <% end %>
 
   <div class="mb-3">
-    <%= submit_tag(t(".continue"), :name => "continue", :id => "continue", :class => "btn btn-primary", :tabindex => 6) %>
+    <%= submit_tag(t(".continue"), :name => "continue", :id => "continue", :class => "btn btn-primary", :tabindex => 5) %>
   </div>
 <% end %>
 
index 5571a4232228b90528646e785331395183fcc286..eaf0fdf1582d0473a180b32a0342dc7c30deedd6 100644 (file)
@@ -260,6 +260,8 @@ en:
         agreed_with_pd: "You have also declared that you consider your edits to be in the Public Domain."
         link: "https://osmfoundation.org/wiki/Licence/Contributor_Terms"
         link text: "what is this?"
+        not_agreed_with_pd: "You haven't declared that you consider your edits to be in the Public Domain."
+        pd_link_text: "declare"
       save changes button: Save Changes
       delete_account: Delete Account...
     go_public:
@@ -305,9 +307,6 @@ en:
         read_ct: "I have read and agree to the above contributor terms"
         tou_explain_html: "These %{tou_link} govern the use of the website and other infrastructure provided by the OSMF. Please click on the link, read and agree to the text."
         read_tou: "I have read and agree to the Terms of Use"
-        consider_pd: "In addition to the above, I consider my contributions to be in the Public Domain"
-        consider_pd_why: "what's this?"
-        consider_pd_why_url: https://osmfoundation.org/wiki/Licence_and_Legal_FAQ/Why_would_I_want_my_contributions_to_be_public_domain
         guidance_info_html: "Information to help understand these terms: a %{readable_summary_link} and some %{informal_translations_link}"
         readable_summary: human readable summary
         informal_translations: informal translations
@@ -325,6 +324,17 @@ en:
         terms_declined_html: We are sorry that you have decided to not accept the new Contributor Terms. For more information, please see %{terms_declined_link}.
         terms_declined_link: this wiki page
         terms_declined_url: https://wiki.openstreetmap.org/wiki/Contributor_Terms_Declined
+    pd_declarations:
+      show:
+        title: Consider my contributions to be in the Public Domain
+        consider_pd: "I consider my contributions to be in the Public Domain"
+        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}"
@@ -2785,9 +2795,6 @@ en:
         privacy_policy_url: https://osmfoundation.org/wiki/Privacy_Policy
         privacy_policy_title: OSMF privacy policy including section on email addresses
         html: 'Your address is not displayed publicly, see our %{privacy_policy_link} for more information.'
-      consider_pd_html: "I consider my contributions to be in the %{consider_pd_link}."
-      consider_pd: "public domain"
-      consider_pd_url: https://osmfoundation.org/wiki/Licence_and_Legal_FAQ/Why_would_I_want_my_contributions_to_be_public_domain
       or: "or"
       use external auth: "or sign up with a third party"
     no_such_user:
index 45fc19f2c295f3ff3834fd92ed9430d83de23416..3971494aa155d1851cb63164283ee124d4bd54ec 100644 (file)
@@ -298,6 +298,7 @@ OpenStreetMap::Application.routes.draw do
   resource :account, :only => [:edit, :update, :destroy] do
     scope :module => :accounts do
       resource :terms, :only => [:show, :update]
+      resource :pd_declaration, :only => [:show, :create]
       resource :deletion, :only => :show
     end
   end
diff --git a/test/controllers/accounts/pd_declarations_controller_test.rb b/test/controllers/accounts/pd_declarations_controller_test.rb
new file mode 100644 (file)
index 0000000..be0d46f
--- /dev/null
@@ -0,0 +1,92 @@
+require "test_helper"
+
+module Accounts
+  class PdDeclarationsControllerTest < ActionDispatch::IntegrationTest
+    ##
+    # test all routes which lead to this controller
+    def test_routes
+      assert_routing(
+        { :path => "/account/pd_declaration", :method => :get },
+        { :controller => "accounts/pd_declarations", :action => "show" }
+      )
+      assert_routing(
+        { :path => "/account/pd_declaration", :method => :post },
+        { :controller => "accounts/pd_declarations", :action => "create" }
+      )
+    end
+
+    def test_show_not_logged_in
+      get account_pd_declaration_path
+
+      assert_redirected_to login_path(:referer => account_pd_declaration_path)
+    end
+
+    def test_show_agreed
+      user = create(:user)
+      session_for(user)
+
+      get account_pd_declaration_path
+
+      assert_response :success
+    end
+
+    def test_create_not_logged_in
+      post account_pd_declaration_path
+
+      assert_response :forbidden
+    end
+
+    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
index 76888466626f049f98860f8d11fc3c1a0bf48fb8..55b30506b41f1bba226869a57125ba088e91bb9b 100644 (file)
@@ -52,13 +52,12 @@ module Accounts
       user = create(:user, :terms_seen => false, :terms_agreed => nil)
       session_for(user)
 
-      put account_terms_path, :params => { :user => { :consider_pd => true }, :read_ct => 1, :read_tou => 1 }
+      put account_terms_path, :params => { :read_ct => 1, :read_tou => 1 }
       assert_redirected_to edit_account_path
       assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
 
       user.reload
 
-      assert user.consider_pd
       assert_not_nil user.terms_agreed
       assert user.terms_seen
     end
@@ -67,13 +66,12 @@ module Accounts
       user = create(:user, :terms_seen => false, :terms_agreed => nil)
       session_for(user)
 
-      put account_terms_path, :params => { :user => { :consider_pd => true }, :referer => "/test", :read_ct => 1, :read_tou => 1 }
+      put account_terms_path, :params => { :referer => "/test", :read_ct => 1, :read_tou => 1 }
       assert_redirected_to "/test"
       assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
 
       user.reload
 
-      assert user.consider_pd
       assert_not_nil user.terms_agreed
       assert user.terms_seen
     end
index 1a53f62daadea43a37615c63777b23edfce4ab7e..5d75c508dd80f3bed6deecaf2f6b8cddd016ac90 100644 (file)
@@ -34,8 +34,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                :params => { :user => { :email => dup_email,
                                        :display_name => display_name,
                                        :pass_crypt => "testtest",
-                                       :pass_crypt_confirmation => "testtest",
-                                       :consider_pd => "1" } }
+                                       :pass_crypt_confirmation => "testtest" } }
         end
       end
     end
@@ -57,8 +56,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                                        :pass_crypt => "testtest",
                                        :pass_crypt_confirmation => "testtest",
                                        :auth_provider => "google",
-                                       :auth_uid => "123454321",
-                                       :consider_pd => "1" } }
+                                       :auth_uid => "123454321" } }
         end
       end
     end
@@ -97,8 +95,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                :params => { :user => { :email => email,
                                        :display_name => display_name,
                                        :pass_crypt => "testtest",
-                                       :pass_crypt_confirmation => "blahblah",
-                                       :consider_pd => "1" } }
+                                       :pass_crypt_confirmation => "blahblah" } }
         end
       end
     end
@@ -117,8 +114,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                :params => { :user => { :email => email,
                                        :display_name => dup_display_name,
                                        :auth_provider => "google",
-                                       :auth_uid => "123454321",
-                                       :consider_pd => "1" } }
+                                       :auth_uid => "123454321" } }
         end
       end
     end
@@ -138,8 +134,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                :params => { :user => { :email => new_email,
                                        :display_name => display_name,
                                        :pass_crypt => "testtest",
-                                       :pass_crypt_confirmation => "testtest",
-                                       :consider_pd => "1" } }
+                                       :pass_crypt_confirmation => "testtest" } }
           assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
           follow_redirect!
         end
@@ -192,8 +187,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                :params => { :user => { :email => new_email,
                                        :display_name => display_name,
                                        :pass_crypt => password,
-                                       :pass_crypt_confirmation => password,
-                                       :consider_pd => "1" },
+                                       :pass_crypt_confirmation => password },
                             :referer => referer }
           assert_response(:redirect)
           assert_redirected_to :controller => :confirmations, :action => :confirm, :display_name => display_name
@@ -254,8 +248,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                :params => { :user => { :email => new_email,
                                        :display_name => display_name,
                                        :auth_provider => "openid",
-                                       :auth_uid => auth_uid,
-                                       :consider_pd => "1" } }
+                                       :auth_uid => auth_uid } }
         end
       end
     end
@@ -330,8 +323,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                :params => { :user => { :email => new_email,
                                        :display_name => display_name,
                                        :auth_provider => "openid",
-                                       :auth_uid => auth_uid,
-                                       :consider_pd => "1" } }
+                                       :auth_uid => auth_uid } }
           follow_redirect!
         end
       end
@@ -392,8 +384,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                :params => { :user => { :email => new_email,
                                        :display_name => display_name,
                                        :auth_provider => "google",
-                                       :auth_uid => auth_uid,
-                                       :consider_pd => "1" },
+                                       :auth_uid => auth_uid },
                             :email_hmac => email_hmac }
           assert_redirected_to welcome_path
           follow_redirect!
@@ -479,8 +470,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                                        :email_hmac => email_hmac,
                                        :display_name => display_name,
                                        :auth_provider => "google",
-                                       :auth_uid => auth_uid,
-                                       :consider_pd => "1" } }
+                                       :auth_uid => auth_uid } }
           assert_response :redirect
           follow_redirect!
         end
@@ -541,8 +531,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                :params => { :user => { :email => new_email,
                                        :display_name => display_name,
                                        :auth_provider => "facebook",
-                                       :auth_uid => auth_uid,
-                                       :consider_pd => "1" },
+                                       :auth_uid => auth_uid },
                             :email_hmac => email_hmac }
           assert_redirected_to welcome_path
           follow_redirect!
@@ -628,8 +617,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                                        :email_hmac => email_hmac,
                                        :display_name => display_name,
                                        :auth_provider => "facebook",
-                                       :auth_uid => auth_uid,
-                                       :consider_pd => "1" } }
+                                       :auth_uid => auth_uid } }
           assert_response :redirect
           follow_redirect!
         end
@@ -689,8 +677,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                :params => { :user => { :email => new_email,
                                        :display_name => display_name,
                                        :auth_provider => "microsoft",
-                                       :auth_uid => auth_uid,
-                                       :consider_pd => "1" },
+                                       :auth_uid => auth_uid },
                             :email_hmac => email_hmac }
           assert_redirected_to welcome_path
           follow_redirect!
@@ -775,8 +762,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                                        :email_hmac => email_hmac,
                                        :display_name => display_name,
                                        :auth_provider => "microsoft",
-                                       :auth_uid => auth_uid,
-                                       :consider_pd => "1" } }
+                                       :auth_uid => auth_uid } }
           assert_response :redirect
           follow_redirect!
         end
@@ -926,8 +912,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                                        :email_hmac => email_hmac,
                                        :display_name => display_name,
                                        :auth_provider => "github",
-                                       :auth_uid => auth_uid,
-                                       :consider_pd => "1" } }
+                                       :auth_uid => auth_uid } }
           assert_response :redirect
           follow_redirect!
         end
@@ -1076,8 +1061,7 @@ class UserCreationTest < ActionDispatch::IntegrationTest
                                        :email_hmac => email_hmac,
                                        :display_name => display_name,
                                        :auth_provider => "wikipedia",
-                                       :auth_uid => auth_uid,
-                                       :consider_pd => "1" } }
+                                       :auth_uid => auth_uid } }
           assert_response :redirect
           follow_redirect!
         end
diff --git a/test/system/account_pd_declaration_test.rb b/test/system/account_pd_declaration_test.rb
new file mode 100644 (file)
index 0000000..d58484c
--- /dev/null
@@ -0,0 +1,46 @@
+require "application_system_test_case"
+
+class AccountPdDeclarationTest < ApplicationSystemTestCase
+  def setup
+    @user = create(:user, :display_name => "test user")
+    sign_in_as(@user)
+  end
+
+  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
+
+  test "show disabled checkbox if declaration was made" do
+    @user.update(:consider_pd => true)
+
+    visit account_pd_declaration_path
+
+    within_content_body do
+      assert_checked_field "I consider my contributions to be in the Public Domain", :disabled => true
+      assert_button "Confirm", :disabled => true
+    end
+  end
+end