Skip to content

Commit

Permalink
gem
Browse files Browse the repository at this point in the history
  • Loading branch information
qinmingyuan committed Mar 6, 2024
1 parent daaa581 commit 1315a99
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -288,6 +293,7 @@ DEPENDENCIES
debug
listen
pg
propshaft
puma
rails
rails_com!
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/growth/admin/aim_codes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Growth::Admin::AimCodesController < Growth::Admin::BaseController

end
3 changes: 3 additions & 0 deletions app/views/growth/admin/aim_codes/_base/_index_tbody.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<td><%= model.controller_path %></td>
<td><%= model.action_name %></td>
<td><%= model.code %></td>
3 changes: 3 additions & 0 deletions app/views/growth/admin/aim_codes/_base/_index_thead.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<th><%= AimCode.human_attribute_name(:controller_path) %></th>
<th><%= AimCode.human_attribute_name(:action_name) %></th>
<th><%= AimCode.human_attribute_name(:code) %></th>
3 changes: 3 additions & 0 deletions app/views/growth/admin/aim_codes/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= f.text_field :controller_path %>
<%= f.text_field :action_name %>
<%= f.text_field :code %>
12 changes: 12 additions & 0 deletions app/views/growth/admin/aim_codes/_show_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<tr>
<td class="has-text-right"><%= AimCode.human_attribute_name(:controller_path) %></td>
<td><%= @aim_code.controller_path %></td>
</tr>
<tr>
<td class="has-text-right"><%= AimCode.human_attribute_name(:action_name) %></td>
<td><%= @aim_code.action_name %></td>
</tr>
<tr>
<td class="has-text-right"><%= AimCode.human_attribute_name(:code) %></td>
<td><%= @aim_code.code %></td>
</tr>
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
62 changes: 62 additions & 0 deletions test/controllers/growth/admin/aim_codes_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/dummy
45 changes: 45 additions & 0 deletions test/system/growth/admin/aim_codes_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1315a99

Please sign in to comment.