Skip to content

Commit

Permalink
Obey rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
kinoppyd committed Mar 21, 2024
1 parent ddc6e4b commit 46cff2d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 34 deletions.
14 changes: 7 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ruby '3.3.0'

gem 'rails', '~> 7.1.3.2'

gem "propshaft"
gem 'propshaft'

# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
Expand All @@ -20,9 +20,9 @@ gem 'rack-contrib', '~> 2.3.0'
gem 'rails-i18n', '~> 7.0.0'

gem 'jsbundling-rails', '~> 1.2'
gem "turbo-rails", "~> 2.0"
gem "stimulus-rails", "~> 1.3"
gem "tailwindcss-rails", "~> 2.0"
gem 'stimulus-rails', '~> 1.3'
gem 'tailwindcss-rails', '~> 2.0'
gem 'turbo-rails', '~> 2.0'

gem 'imgkit'
install_if -> { RUBY_PLATFORM =~ /darwin/ } do
Expand All @@ -36,14 +36,14 @@ group :development, :test do
end

group :development do
gem 'erb-formatter', '~> 0.4.3'
gem 'listen', '~> 3.3'
gem "erb-formatter", "~> 0.4.3"
end

group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem 'capybara'
gem 'selenium-webdriver'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
16 changes: 11 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def set_user

def set_plan
@plan = @user.plans.where(event: @event).recent&.first ||
@user.plans.build(title: "My RubyKaigi #{@event.name} set list",
description: "Enjoy my RubyKaigi #{@event.name} set list",
public: true,
event: @event)
@user.plans.build(title: "My RubyKaigi #{@event.name} set list",
description: "Enjoy my RubyKaigi #{@event.name} set list",
public: true,
event: @event)
end

def not_found(err)
Expand All @@ -50,7 +50,13 @@ def create_and_set_user
def set_locale
return unless params.key?('locale')

locale = ActiveSupport::TimeZone.all.map { |z| z.tzinfo.identifier }.include?(params['locale']) ? params['locale'] : 'Etc/UTC'
locale = if ActiveSupport::TimeZone.all.map do |z|
z.tzinfo.identifier
end.include?(params['locale'])
params['locale']
else
'Etc/UTC'
end
session[:locale] = locale
end

Expand Down
39 changes: 24 additions & 15 deletions app/controllers/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,15 @@ def show
end

def update
target = if plan_add_or_remove?
add_and_remove_plans
elsif params[:edit_memo_schedule_id]
edit_memo
elsif params[:plan][:description]
edit_description
elsif params[:plan][:public]
edit_password_and_visibility
elsif params[:plan][:title]
edit_title
else
head :bad_request
end
target = switch_update_type_and_exec

if plan_add_or_remove? && params[:mode] == 'schedule'
redirect_to event_schedules_path(event_name: @event.name)
elsif plan_add_or_remove? && params[:mode] == 'plan'
redirect_to event_plan_path(@plan, event_name: @event.name)
elsif target
render 'schedules/_card', locals: { schedule: target, mode: params[:edit_memo_schedule_id] ? :plan : :schedule, inactive: false }
render 'schedules/_card',
locals: { schedule: target, mode: params[:edit_memo_schedule_id] ? :plan : :schedule, inactive: false }
else
redirect_to event_plan_url(@plan, event_name: @event.name)
end
Expand All @@ -59,12 +48,32 @@ def create

private

def switch_update_type_and_exec
if plan_add_or_remove?
add_and_remove_plans
elsif params[:edit_memo_schedule_id]
edit_memo
elsif params[:plan][:description]
edit_description
elsif params[:plan][:public]
edit_password_and_visibility
elsif params[:plan][:title]
edit_title
else
head :bad_request
end
end

def plan_params
params.require(:plan).permit(:title, :description, :public, :initial)
end

def plan_add_or_remove?
params[:add_schedule_id] || params[:remove_schedule_id] || (params[:plan] && (params[:plan][:add_schedule_id] || params[:plan][:remove_schedule_id]))
if params[:plan]
params[:plan][:add_schedule_id] || params[:plan][:remove_schedule_id]
else
params[:add_schedule_id] || params[:remove_schedule_id]
end
end

def redirect_path_with_identifier(target)
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Rails.application.routes.draw do
root to: redirect('/2023')


scope '/:event_name', as: 'event' do
get '/', to: 'static#top'
get '/terms-of-service', to: 'static#terms_of_service'
Expand Down
4 changes: 3 additions & 1 deletion test/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "test_helper"
# frozen_string_literal: true

require 'test_helper'

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
Expand Down
12 changes: 7 additions & 5 deletions test/system/schedules_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require "application_system_test_case"
# frozen_string_literal: true

require 'application_system_test_case'

class SchedulesTest < ApplicationSystemTestCase
test 'schedule has all days buttons' do
Expand Down Expand Up @@ -69,12 +71,12 @@ class SchedulesTest < ApplicationSystemTestCase
find(class: ['confirm-terms-of-service-button']).click

# wait for turbo frame
if has_selector?('dialog', visible: true, wait: (0.25).seconds)
if has_selector?('dialog', visible: true, wait: 0.25.seconds)
has_no_selector?('dialog', visible: true, wait: 1.seconds)
end

table_rows = all('tr')
assert table_rows[2].all(class: ['add-plan-button']).all? { _1.disabled? }
assert table_rows[2].all(class: ['add-plan-button']).all?(&:disabled?)
end

test 'when one schedule added to plan, that schedule button to be remove button' do
Expand All @@ -84,11 +86,11 @@ class SchedulesTest < ApplicationSystemTestCase
find(class: ['confirm-terms-of-service-button']).click

# wait for turbo frame
if has_selector?('dialog', visible: true, wait: (0.25).seconds)
if has_selector?('dialog', visible: true, wait: 0.25.seconds)
has_no_selector?('dialog', visible: true, wait: 1.seconds)
end

table_rows = all('tr')
assert table_rows[2].find_button(class: ['remove-plan-button'])
end
end
end

0 comments on commit 46cff2d

Please sign in to comment.