-
-
Save Insood/a24b12eea9999a47e8cc7692734c8636 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Router::SectionsController < ApplicationController | |
def index | |
@sections = Router::Section.all() | |
end | |
def show | |
@section = Router::Section.includes(steps: :component_groups) | |
.order("router_steps.position ASC") | |
.find(params[:id]) | |
end | |
def edit | |
@section = Router::Section.includes(steps: :component_groups) | |
.order("router_steps.position ASC") | |
.find(params[:id]) | |
authorize(@section) | |
@section.steps.build | |
end | |
def update | |
@section = Router::Section.includes(steps: :component_groups) | |
.order("router_steps.position ASC") | |
.find(params[:id]) | |
authorize(@section) | |
@section.update(params_for_section) | |
if @section.save then | |
flash[:success] = "Updated" | |
redirect_to @section | |
else | |
flash.now[:danger] = "Could not update" | |
render :edit | |
end | |
end | |
private | |
def params_for_section | |
params.require(:router_section).permit(steps_attributes: [:description, :preface, :postface]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "test_helper" | |
class Router::SectionsControllerTest < ActionDispatch::IntegrationTest | |
include Devise::Test::IntegrationHelpers | |
def test_index | |
get router_sections_path | |
assert_response :success | |
end | |
def test_show | |
@section = router_sections(:sample) | |
get router_section_path(@section) | |
assert_response :success | |
end | |
def test_edit_no_login | |
@section = router_sections(:sample) | |
get edit_router_section_path(@section) | |
assert_redirected_to root_path | |
end | |
def test_can_edit_if_admin | |
@section = router_sections(:sample) | |
login = login(:sample) | |
sign_in(login) | |
User.any_instance.stubs(:has_role?).returns( lambda { |role| [Roles::ProductionAdmin].include?(role)} ) | |
get edit_router_section_path(@section) | |
assert_response :success | |
end | |
def test_update_no_login | |
@section = router_sections(:sample) | |
new_description = "New description!" | |
patch router_section_path(@section), router_section: { description: new_description} | |
assert_redirected_to root_path | |
end | |
def test_update_if_login | |
@section = router_sections(:sample) | |
new_description = "New description!" | |
login = login(:sample) | |
sign_in(login) | |
User.any_instance.stubs(:has_role?).returns( lambda { |role| [Roles::ProductionAdmin].include?(role)} ) | |
patch router_section_path(@section), router_section: { description: new_description} | |
assert_redirected_to @section | |
end | |
def test_update_nested_attributes | |
skip "Later :(" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment