From e5809207a9454fd01a9b00f677e4f246e8ed5ae9 Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Fri, 16 Jan 2015 07:50:36 +0100 Subject: [PATCH] created subcategories --- Gemfile | 3 ++ Gemfile.lock | 3 ++ README.md | 27 +++++++++- README.rdoc | 28 ----------- app/controllers/sub_categories_controller.rb | 5 ++ app/helpers/sub_categories_helper.rb | 2 + app/models/Category.rb | 1 + app/models/sub_category.rb | 3 ++ config/routes.rb | 1 + .../sub_categories_controller_test.rb | 49 +++++++++++++++++++ test/fixtures/sub_categories.yml | 9 ++++ test/models/sub_category_test.rb | 7 +++ 12 files changed, 109 insertions(+), 29 deletions(-) delete mode 100644 README.rdoc create mode 100644 app/controllers/sub_categories_controller.rb create mode 100644 app/helpers/sub_categories_helper.rb create mode 100644 app/models/sub_category.rb create mode 100644 test/controllers/sub_categories_controller_test.rb create mode 100644 test/fixtures/sub_categories.yml create mode 100644 test/models/sub_category_test.rb diff --git a/Gemfile b/Gemfile index 0cb6416..511cecf 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,9 @@ gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc +# great server +gem 'puma' + # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/Gemfile.lock b/Gemfile.lock index 0d024a3..2f8f7a1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -87,6 +87,8 @@ GEM nokogiri (1.6.5) mini_portile (~> 0.6.0) pg (0.18.1) + puma (2.10.2) + rack (>= 1.1, < 2.0) rack (1.6.0) rack-test (0.6.3) rack (>= 1.0) @@ -164,6 +166,7 @@ DEPENDENCIES jbuilder (~> 2.0) jquery-rails pg + puma rails (= 4.2.0) sass-rails (~> 5.0) sdoc (~> 0.4.0) diff --git a/README.md b/README.md index c7ca109..f6922ce 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,27 @@ -# ribica-back-office +# Ribica Back Office + Rails interface for administration + +## Configuration + +Configure config/database.yml to point to same database as config.rb in front office + +## Active scaffold + +Customization documentation is here: http://activescaffold.com/ + +Example of generating scaffold for category model + +`rails g active_scaffold Category name:string` + +## Handling shared models + +Some of models will necesarrily be shared between front and back office. +Migrations for those models *must be in front office* and +back office will just have a model file with custom code if needed. +The reason is that we want front office to be standalone with a different +backoffice (for sellingtechnology to other businesses and stuff). + +When generating active scaffold - migration is generated by default so it +needs to be removed before using it. + diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index dd4e97e..0000000 --- a/README.rdoc +++ /dev/null @@ -1,28 +0,0 @@ -== README - -This README would normally document whatever steps are necessary to get the -application up and running. - -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... - - -Please feel free to use a different markup language if you do not plan to run -rake doc:app. diff --git a/app/controllers/sub_categories_controller.rb b/app/controllers/sub_categories_controller.rb new file mode 100644 index 0000000..c18be5c --- /dev/null +++ b/app/controllers/sub_categories_controller.rb @@ -0,0 +1,5 @@ +class SubCategoriesController < ApplicationController + active_scaffold :"sub_category" do |conf| + conf.columns = [:name] + end +end diff --git a/app/helpers/sub_categories_helper.rb b/app/helpers/sub_categories_helper.rb new file mode 100644 index 0000000..20a2f82 --- /dev/null +++ b/app/helpers/sub_categories_helper.rb @@ -0,0 +1,2 @@ +module SubCategoriesHelper +end \ No newline at end of file diff --git a/app/models/Category.rb b/app/models/Category.rb index d25d10f..46f9479 100644 --- a/app/models/Category.rb +++ b/app/models/Category.rb @@ -1,2 +1,3 @@ class Category < ActiveRecord::Base + has_many :sub_categories end diff --git a/app/models/sub_category.rb b/app/models/sub_category.rb new file mode 100644 index 0000000..70f8332 --- /dev/null +++ b/app/models/sub_category.rb @@ -0,0 +1,3 @@ +class SubCategory < ActiveRecord::Base + belongs_to :category +end diff --git a/config/routes.rb b/config/routes.rb index 99309f8..3320242 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + 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. # See how all your routes lay out with "rake routes". diff --git a/test/controllers/sub_categories_controller_test.rb b/test/controllers/sub_categories_controller_test.rb new file mode 100644 index 0000000..d873c5f --- /dev/null +++ b/test/controllers/sub_categories_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class SubCategoriesControllerTest < ActionController::TestCase + setup do + @sub_category = sub_categories(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:sub_categories) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create sub_category" do + assert_difference('SubCategory.count') do + post :create, sub_category: { category_id: @sub_category.category_id, name: @sub_category.name } + end + + assert_redirected_to sub_category_path(assigns(:sub_category)) + end + + test "should show sub_category" do + get :show, id: @sub_category + assert_response :success + end + + test "should get edit" do + get :edit, id: @sub_category + assert_response :success + end + + test "should update sub_category" do + patch :update, id: @sub_category, sub_category: { category_id: @sub_category.category_id, name: @sub_category.name } + assert_redirected_to sub_category_path(assigns(:sub_category)) + end + + test "should destroy sub_category" do + assert_difference('SubCategory.count', -1) do + delete :destroy, id: @sub_category + end + + assert_redirected_to sub_categories_path + end +end diff --git a/test/fixtures/sub_categories.yml b/test/fixtures/sub_categories.yml new file mode 100644 index 0000000..7f261e7 --- /dev/null +++ b/test/fixtures/sub_categories.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + category_id: 1 + +two: + name: MyString + category_id: 1 diff --git a/test/models/sub_category_test.rb b/test/models/sub_category_test.rb new file mode 100644 index 0000000..4f5e8d5 --- /dev/null +++ b/test/models/sub_category_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SubCategoryTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end