]> git.openstreetmap.org Git - rails.git/commitdiff
Add pd declaration create action
authorAnton Khorev <tony29@yandex.ru>
Fri, 17 Jan 2025 15:27:47 +0000 (18:27 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 18 Jan 2025 16:16:17 +0000 (19:16 +0300)
app/abilities/ability.rb
app/controllers/accounts/pd_declarations_controller.rb
config/routes.rb
test/controllers/accounts/pd_declarations_controller_test.rb

index 44b0ba93d2af8d402b9316f6eabcafe81172bced..f461314540c25a54bead71854dfd516e8499fe56 100644 (file)
@@ -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 3d90d250e65d0aca8cba6ce290b737cbd5b9d234..f6740f77787f1850afaf2690fa67614c391ceb5d 100644 (file)
@@ -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
index 4172069b9396e03f83f8a7461d9effa9992ce1f3..aa2ae815b7bc45be43c9193a9b42025a3f37be4e 100644 (file)
@@ -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
index 4b961e3268e44b112c1c1cf2b6b8cbf45d675bda..d2bbd70d2480b4e6f65a0d9d2379aa909bfb2b41 100644 (file)
@@ -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