From 7d6ac34fbcc86f9750ea4590043f12e24b76d057 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Fri, 17 Jan 2025 18:27:47 +0300 Subject: [PATCH] Add pd declaration create action --- app/abilities/ability.rb | 1 + .../accounts/pd_declarations_controller.rb | 4 ++++ config/routes.rb | 2 +- .../pd_declarations_controller_test.rb | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 44b0ba93d..f46131454 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -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 diff --git a/app/controllers/accounts/pd_declarations_controller.rb b/app/controllers/accounts/pd_declarations_controller.rb index 3d90d250e..f6740f777 100644 --- a/app/controllers/accounts/pd_declarations_controller.rb +++ b/app/controllers/accounts/pd_declarations_controller.rb @@ -8,5 +8,9 @@ module Accounts authorize_resource :class => :account_pd_declaration def show; end + + def create + redirect_to edit_account_path + end end end diff --git a/config/routes.rb b/config/routes.rb index 4172069b9..aa2ae815b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -279,7 +279,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 + 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 index 4b961e326..d2bbd70d2 100644 --- a/test/controllers/accounts/pd_declarations_controller_test.rb +++ b/test/controllers/accounts/pd_declarations_controller_test.rb @@ -9,6 +9,10 @@ module Accounts { :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 @@ -25,5 +29,20 @@ module Accounts assert_response :success end + + def test_create_not_logged_in + post account_pd_declaration_path + + assert_response :forbidden + end + + def test_create + user = create(:user) + session_for(user) + + post account_pd_declaration_path + + assert_redirected_to edit_account_path + end end end -- 2.39.5