added sections
This commit is contained in:
4
app/controllers/sections_controller.rb
Normal file
4
app/controllers/sections_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class SectionsController < ApplicationController
|
||||||
|
active_scaffold :"section" do |conf|
|
||||||
|
end
|
||||||
|
end
|
||||||
2
app/helpers/sections_helper.rb
Normal file
2
app/helpers/sections_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module SectionsHelper
|
||||||
|
end
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
class Category < ActiveRecord::Base
|
class Category < ActiveRecord::Base
|
||||||
has_many :sub_categories
|
has_many :sub_categories
|
||||||
|
belongs_to :section
|
||||||
end
|
end
|
||||||
|
|||||||
3
app/models/section.rb
Normal file
3
app/models/section.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
class Section < ActiveRecord::Base
|
||||||
|
has_many :categories
|
||||||
|
end
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
resources :sections do as_routes end
|
||||||
resources :sub_categories do as_routes end
|
resources :sub_categories do as_routes end
|
||||||
resources :categories do as_routes end
|
resources :categories do as_routes end
|
||||||
# The priority is based upon order of creation: first created -> highest priority.
|
# The priority is based upon order of creation: first created -> highest priority.
|
||||||
|
|||||||
49
test/controllers/sections_controller_test.rb
Normal file
49
test/controllers/sections_controller_test.rb
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SectionsControllerTest < ActionController::TestCase
|
||||||
|
setup do
|
||||||
|
@section = sections(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:sections)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create section" do
|
||||||
|
assert_difference('Section.count') do
|
||||||
|
post :create, section: { name: @section.name }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to section_path(assigns(:section))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show section" do
|
||||||
|
get :show, id: @section
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, id: @section
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update section" do
|
||||||
|
patch :update, id: @section, section: { name: @section.name }
|
||||||
|
assert_redirected_to section_path(assigns(:section))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy section" do
|
||||||
|
assert_difference('Section.count', -1) do
|
||||||
|
delete :destroy, id: @section
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to sections_path
|
||||||
|
end
|
||||||
|
end
|
||||||
7
test/fixtures/sections.yml
vendored
Normal file
7
test/fixtures/sections.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: MyString
|
||||||
7
test/models/section_test.rb
Normal file
7
test/models/section_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SectionTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user