Skip to content

Commit

Permalink
Obey rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
kinoppyd committed Dec 20, 2024
1 parent 0433654 commit b55fa8f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/controllers/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def add_plan(id)
end

def check_user_owns_plan
render status: :bad_request, body: nil if @plan.nil?
render status: :bad_request, body: nil if @plan.nil?
render status: :forbidden, body: nil unless @user.plans.include?(@plan)
end

Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
resources :items, only: %i[update destroy]
end

resolve('PlanSchedule') { [:event, :item] }
resolve('PlanSchedule') { %i[event item] }

resources :teams, except: :index do
resources :members, only: %i[create update destroy]
Expand Down
24 changes: 16 additions & 8 deletions test/controllers/items_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,32 @@ def setup

test 'Add new item to plan' do
assert_difference('PlanSchedule.count', 1) do
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id), params: { schedule_id: schedules(:six).id }
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id),
params: { schedule_id: schedules(:six).id }
end
assert_redirected_to event_plan_path(plans(:one), event_name: events(:party).name)
end

test 'Add new item to plan with turbo frames' do
assert_difference('PlanSchedule.count', 1) do
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id), params: { schedule_id: schedules(:six).id }, as: :turbo_stream
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id),
params: { schedule_id: schedules(:six).id }, as: :turbo_stream
end
assert_response :ok
end

test 'Reject add new item to plan when crossover item has exists' do
assert_no_difference('PlanSchedule.count') do
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id), params: { schedule_id: schedules(:one_crossover).id }
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id),
params: { schedule_id: schedules(:one_crossover).id }
end
assert_redirected_to event_plan_path(plans(:one), event_name: events(:party).name)
end

test 'Reject add new item to plan when crossover item has exists with turbo frames' do
assert_no_difference('PlanSchedule.count') do
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id), params: { schedule_id: schedules(:one_crossover).id }, as: :turbo_stream
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id),
params: { schedule_id: schedules(:one_crossover).id }, as: :turbo_stream
end
assert_redirected_to event_plan_path(plans(:one), event_name: events(:party).name)
end
Expand All @@ -41,7 +45,8 @@ def setup
plan.initial = true
plan.save!

post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id), params: { schedule_id: schedules(:six).id }
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id),
params: { schedule_id: schedules(:six).id }
plan.reload

assert_not plan.initial
Expand All @@ -52,22 +57,25 @@ def setup
plan.initial = true
plan.save!

post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id), params: { schedule_id: schedules(:one_crossover).id }
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id),
params: { schedule_id: schedules(:one_crossover).id }
plan.reload

assert plan.initial
end

test 'Reject add item to plan when item is not belongs to event' do
assert_no_difference('PlanSchedule.count') do
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id), params: { schedule_id: schedules(:dojo_one).id }
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:one).id),
params: { schedule_id: schedules(:dojo_one).id }
end
assert_response :not_found
end

test 'Reject add new item to plan that not owned' do
assert_no_difference('PlanSchedule.count') do
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:two).id), params: { schedule_id: schedules(:six).id }
post event_plan_items_url(event_name: events(:party).name, plan_id: plans(:two).id),
params: { schedule_id: schedules(:six).id }
end
assert_response :forbidden
end
Expand Down
7 changes: 5 additions & 2 deletions test/controllers/plans_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ def setup

test 'Create plan' do
assert_difference('Plan.count') do
post event_plans_path(event_name: events(:dojo).name), params: { plan: { title: 'test', description: 'test', public: true, initial: false } }
post event_plans_path(event_name: events(:dojo).name),
params: { plan: { title: 'test', description: 'test', public: true, initial: false } }
end

assert_redirected_to event_schedules_path(event_name: events(:dojo).name)
end

test 'Create plan with first item' do
assert_difference('PlanSchedule.count') do
post event_plans_path(event_name: events(:dojo).name), params: { plan: { title: 'test', description: 'test', public: true, initial: false, add_schedule_id: schedules(:dojo_one).id }}
post event_plans_path(event_name: events(:dojo).name),
params: { plan: { title: 'test', description: 'test', public: true, initial: false,
add_schedule_id: schedules(:dojo_one).id } }
end

assert_redirected_to event_schedules_path(event_name: events(:dojo).name)
Expand Down

0 comments on commit b55fa8f

Please sign in to comment.