From 1315a99cb97cb7eff5f863729248667e2f05061a Mon Sep 17 00:00:00 2001 From: qinmingyuan Date: Wed, 6 Mar 2024 22:03:45 +0800 Subject: [PATCH] gem --- Gemfile | 1 + Gemfile.lock | 6 ++ .../growth/admin/aim_codes_controller.rb | 3 + .../aim_codes/_base/_index_tbody.html.erb | 3 + .../aim_codes/_base/_index_thead.html.erb | 3 + .../growth/admin/aim_codes/_form.html.erb | 3 + .../admin/aim_codes/_show_table.html.erb | 12 ++++ config/routes.rb | 5 ++ .../growth/admin/aim_codes_controller_test.rb | 62 +++++++++++++++++++ test/dummy | 2 +- test/system/growth/admin/aim_codes_test.rb | 45 ++++++++++++++ 11 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 app/controllers/growth/admin/aim_codes_controller.rb create mode 100644 app/views/growth/admin/aim_codes/_base/_index_tbody.html.erb create mode 100644 app/views/growth/admin/aim_codes/_base/_index_thead.html.erb create mode 100644 app/views/growth/admin/aim_codes/_form.html.erb create mode 100644 app/views/growth/admin/aim_codes/_show_table.html.erb create mode 100644 test/controllers/growth/admin/aim_codes_controller_test.rb create mode 100644 test/system/growth/admin/aim_codes_test.rb diff --git a/Gemfile b/Gemfile index fda4cb7..6412d7a 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gemspec gem 'rails' gem 'pg' gem 'puma' +gem 'propshaft' gem 'rails_extend', github: 'work-design/rails_extend' gem 'rails_com', github: 'work-design/rails_com' diff --git a/Gemfile.lock b/Gemfile.lock index 7ea8949..f9251d4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -209,6 +209,11 @@ GEM mini_portile2 (~> 2.8.2) racc (~> 1.4) pg (1.5.6) + propshaft (0.8.0) + actionpack (>= 7.0.0) + activesupport (>= 7.0.0) + rack + railties (>= 7.0.0) psych (5.1.2) stringio puma (6.4.2) @@ -288,6 +293,7 @@ DEPENDENCIES debug listen pg + propshaft puma rails rails_com! diff --git a/app/controllers/growth/admin/aim_codes_controller.rb b/app/controllers/growth/admin/aim_codes_controller.rb new file mode 100644 index 0000000..997b13b --- /dev/null +++ b/app/controllers/growth/admin/aim_codes_controller.rb @@ -0,0 +1,3 @@ +class Growth::Admin::AimCodesController < Growth::Admin::BaseController + +end diff --git a/app/views/growth/admin/aim_codes/_base/_index_tbody.html.erb b/app/views/growth/admin/aim_codes/_base/_index_tbody.html.erb new file mode 100644 index 0000000..000ff33 --- /dev/null +++ b/app/views/growth/admin/aim_codes/_base/_index_tbody.html.erb @@ -0,0 +1,3 @@ +<%= model.controller_path %> +<%= model.action_name %> +<%= model.code %> diff --git a/app/views/growth/admin/aim_codes/_base/_index_thead.html.erb b/app/views/growth/admin/aim_codes/_base/_index_thead.html.erb new file mode 100644 index 0000000..849cb51 --- /dev/null +++ b/app/views/growth/admin/aim_codes/_base/_index_thead.html.erb @@ -0,0 +1,3 @@ +<%= AimCode.human_attribute_name(:controller_path) %> +<%= AimCode.human_attribute_name(:action_name) %> +<%= AimCode.human_attribute_name(:code) %> diff --git a/app/views/growth/admin/aim_codes/_form.html.erb b/app/views/growth/admin/aim_codes/_form.html.erb new file mode 100644 index 0000000..6813dfb --- /dev/null +++ b/app/views/growth/admin/aim_codes/_form.html.erb @@ -0,0 +1,3 @@ +<%= f.text_field :controller_path %> +<%= f.text_field :action_name %> +<%= f.text_field :code %> diff --git a/app/views/growth/admin/aim_codes/_show_table.html.erb b/app/views/growth/admin/aim_codes/_show_table.html.erb new file mode 100644 index 0000000..fac6291 --- /dev/null +++ b/app/views/growth/admin/aim_codes/_show_table.html.erb @@ -0,0 +1,12 @@ + + <%= AimCode.human_attribute_name(:controller_path) %> + <%= @aim_code.controller_path %> + + + <%= AimCode.human_attribute_name(:action_name) %> + <%= @aim_code.action_name %> + + + <%= AimCode.human_attribute_name(:code) %> + <%= @aim_code.code %> + diff --git a/config/routes.rb b/config/routes.rb index ef0fd71..8e0b312 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,9 @@ Rails.application.routes.draw do + namespace :growth do + namespace :admin do + resources :aim_codes + end + end namespace 'growth', defaults: { business: 'growth' } do namespace :admin, defaults: { namespace: 'admin' } do diff --git a/test/controllers/growth/admin/aim_codes_controller_test.rb b/test/controllers/growth/admin/aim_codes_controller_test.rb new file mode 100644 index 0000000..92b4289 --- /dev/null +++ b/test/controllers/growth/admin/aim_codes_controller_test.rb @@ -0,0 +1,62 @@ +require 'test_helper' +class Growth::Admin::AimCodesControllerTest < ActionDispatch::IntegrationTest + + setup do + @aim_code = aim_codes(:one) + end + + test 'index ok' do + get url_for(controller: 'growth/admin/aim_codes') + + assert_response :success + end + + test 'new ok' do + get url_for(controller: 'growth/admin/aim_codes') + + assert_response :success + end + + test 'create ok' do + assert_difference('AimCode.count') do + post( + url_for(controller: 'growth/admin/aim_codes', action: 'create'), + params: { aim_code: { action_name: @growth_admin_aim_code.action_name, code: @growth_admin_aim_code.code, controller_path: @growth_admin_aim_code.controller_path } }, + as: :turbo_stream + ) + end + + assert_response :success + end + + test 'show ok' do + get url_for(controller: 'growth/admin/aim_codes', action: 'show', id: @aim_code.id) + + assert_response :success + end + + test 'edit ok' do + get url_for(controller: 'growth/admin/aim_codes', action: 'edit', id: @aim_code.id) + + assert_response :success + end + + test 'update ok' do + patch( + url_for(controller: 'growth/admin/aim_codes', action: 'update', id: @aim_code.id), + params: { aim_code: { action_name: @growth_admin_aim_code.action_name, code: @growth_admin_aim_code.code, controller_path: @growth_admin_aim_code.controller_path } }, + as: :turbo_stream + ) + + assert_response :success + end + + test 'destroy ok' do + assert_difference('AimCode.count', -1) do + delete url_for(controller: 'growth/admin/aim_codes', action: 'destroy', id: @aim_code.id), as: :turbo_stream + end + + assert_response :success + end + +end diff --git a/test/dummy b/test/dummy index 297245b..67a13fa 160000 --- a/test/dummy +++ b/test/dummy @@ -1 +1 @@ -Subproject commit 297245b2bd7da13c088c0afeb52e03fd7a79853a +Subproject commit 67a13faa554fb96f06175a9190541cf4fc2c6fb2 diff --git a/test/system/growth/admin/aim_codes_test.rb b/test/system/growth/admin/aim_codes_test.rb new file mode 100644 index 0000000..ee526da --- /dev/null +++ b/test/system/growth/admin/aim_codes_test.rb @@ -0,0 +1,45 @@ +require "application_system_test_case" + +class AimCodesTest < ApplicationSystemTestCase + setup do + @growth_admin_aim_code = growth_admin_aim_codes(:one) + end + + test "visiting the index" do + visit growth_admin_aim_codes_url + assert_selector "h1", text: "Aim codes" + end + + test "should create aim code" do + visit growth_admin_aim_codes_url + click_on "New aim code" + + fill_in "Action name", with: @growth_admin_aim_code.action_name + fill_in "Code", with: @growth_admin_aim_code.code + fill_in "Controller path", with: @growth_admin_aim_code.controller_path + click_on "Create Aim code" + + assert_text "Aim code was successfully created" + click_on "Back" + end + + test "should update Aim code" do + visit growth_admin_aim_code_url(@growth_admin_aim_code) + click_on "Edit this aim code", match: :first + + fill_in "Action name", with: @growth_admin_aim_code.action_name + fill_in "Code", with: @growth_admin_aim_code.code + fill_in "Controller path", with: @growth_admin_aim_code.controller_path + click_on "Update Aim code" + + assert_text "Aim code was successfully updated" + click_on "Back" + end + + test "should destroy Aim code" do + visit growth_admin_aim_code_url(@growth_admin_aim_code) + click_on "Destroy this aim code", match: :first + + assert_text "Aim code was successfully destroyed" + end +end