diff --git a/app/controllers/sections_controller.rb b/app/controllers/sections_controller.rb new file mode 100644 index 0000000..a93ad01 --- /dev/null +++ b/app/controllers/sections_controller.rb @@ -0,0 +1,4 @@ +class SectionsController < ApplicationController + active_scaffold :"section" do |conf| + end +end diff --git a/app/helpers/sections_helper.rb b/app/helpers/sections_helper.rb new file mode 100644 index 0000000..e0106de --- /dev/null +++ b/app/helpers/sections_helper.rb @@ -0,0 +1,2 @@ +module SectionsHelper +end \ No newline at end of file diff --git a/app/models/Category.rb b/app/models/Category.rb index 46f9479..470d4db 100644 --- a/app/models/Category.rb +++ b/app/models/Category.rb @@ -1,3 +1,4 @@ class Category < ActiveRecord::Base has_many :sub_categories + belongs_to :section end diff --git a/app/models/section.rb b/app/models/section.rb new file mode 100644 index 0000000..1582577 --- /dev/null +++ b/app/models/section.rb @@ -0,0 +1,3 @@ +class Section < ActiveRecord::Base + has_many :categories +end diff --git a/config/routes.rb b/config/routes.rb index 3320242..1972528 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :sections do as_routes end resources :sub_categories do as_routes end resources :categories do as_routes end # The priority is based upon order of creation: first created -> highest priority. diff --git a/test/controllers/sections_controller_test.rb b/test/controllers/sections_controller_test.rb new file mode 100644 index 0000000..c037a46 --- /dev/null +++ b/test/controllers/sections_controller_test.rb @@ -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 diff --git a/test/fixtures/sections.yml b/test/fixtures/sections.yml new file mode 100644 index 0000000..56066c6 --- /dev/null +++ b/test/fixtures/sections.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/section_test.rb b/test/models/section_test.rb new file mode 100644 index 0000000..b8b5039 --- /dev/null +++ b/test/models/section_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SectionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end