From d09bc71aae433c2aad656ad7f79e16a588f7e9f5 Mon Sep 17 00:00:00 2001 From: Senad Uka Date: Sun, 18 Jan 2015 10:24:15 +0100 Subject: [PATCH] created items and configured back office ui a bit --- Gemfile | 3 ++ Gemfile.lock | 9 ++++ app/controllers/items_controller.rb | 5 ++ app/controllers/media_types_controller.rb | 4 ++ .../multi_media_descriptions_controller.rb | 5 ++ app/controllers/units_controller.rb | 4 ++ app/helpers/items_helper.rb | 4 ++ app/helpers/media_types_helper.rb | 2 + .../multi_media_descriptions_helper.rb | 2 + app/helpers/units_helper.rb | 2 + app/models/Category.rb | 4 -- app/models/category.rb | 4 ++ app/models/item.rb | 4 ++ app/models/media_type.rb | 3 ++ app/models/multi_media_description.rb | 5 ++ app/models/section.rb | 2 +- app/models/unit.rb | 2 + app/views/layouts/application.html.erb | 9 +++- config/cloudinary.yml | 19 +++++++ config/routes.rb | 7 ++- test/controllers/items_controller_test.rb | 49 +++++++++++++++++++ .../media_types_controller_test.rb | 49 +++++++++++++++++++ ...ulti_media_descriptions_controller_test.rb | 49 +++++++++++++++++++ test/controllers/units_controller_test.rb | 49 +++++++++++++++++++ test/fixtures/items.yml | 25 ++++++++++ test/fixtures/media_types.yml | 7 +++ test/fixtures/multi_media_descriptions.yml | 11 +++++ test/fixtures/units.yml | 9 ++++ test/models/item_test.rb | 7 +++ test/models/media_type_test.rb | 7 +++ test/models/multi_media_description_test.rb | 7 +++ test/models/unit_test.rb | 7 +++ 32 files changed, 368 insertions(+), 7 deletions(-) create mode 100644 app/controllers/items_controller.rb create mode 100644 app/controllers/media_types_controller.rb create mode 100644 app/controllers/multi_media_descriptions_controller.rb create mode 100644 app/controllers/units_controller.rb create mode 100644 app/helpers/items_helper.rb create mode 100644 app/helpers/media_types_helper.rb create mode 100644 app/helpers/multi_media_descriptions_helper.rb create mode 100644 app/helpers/units_helper.rb delete mode 100644 app/models/Category.rb create mode 100644 app/models/category.rb create mode 100644 app/models/item.rb create mode 100644 app/models/media_type.rb create mode 100644 app/models/multi_media_description.rb create mode 100644 app/models/unit.rb create mode 100644 config/cloudinary.yml create mode 100644 test/controllers/items_controller_test.rb create mode 100644 test/controllers/media_types_controller_test.rb create mode 100644 test/controllers/multi_media_descriptions_controller_test.rb create mode 100644 test/controllers/units_controller_test.rb create mode 100644 test/fixtures/items.yml create mode 100644 test/fixtures/media_types.yml create mode 100644 test/fixtures/multi_media_descriptions.yml create mode 100644 test/fixtures/units.yml create mode 100644 test/models/item_test.rb create mode 100644 test/models/media_type_test.rb create mode 100644 test/models/multi_media_description_test.rb create mode 100644 test/models/unit_test.rb diff --git a/Gemfile b/Gemfile index 511cecf..8e2e0ee 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,9 @@ gem 'sdoc', '~> 0.4.0', group: :doc # great server gem 'puma' +# for uploading images +gem 'cloudinary' + # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/Gemfile.lock b/Gemfile.lock index 2f8f7a1..a22c30c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,6 +45,7 @@ GEM thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) arel (6.0.0) + aws_cf_signer (0.1.3) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) builder (3.2.2) @@ -52,6 +53,9 @@ GEM columnize (~> 0.8) debugger-linecache (~> 1.2) slop (~> 3.6) + cloudinary (1.0.81) + aws_cf_signer + rest-client coffee-rails (4.1.0) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -84,6 +88,7 @@ GEM mini_portile (0.6.2) minitest (5.5.1) multi_json (1.10.1) + netrc (0.10.2) nokogiri (1.6.5) mini_portile (~> 0.6.0) pg (0.18.1) @@ -119,6 +124,9 @@ GEM rake (10.4.2) rdoc (4.2.0) json (~> 1.4) + rest-client (1.7.2) + mime-types (>= 1.16, < 3.0) + netrc (~> 0.7) sass (3.4.9) sass-rails (5.0.1) railties (>= 4.0.0, < 5.0) @@ -162,6 +170,7 @@ PLATFORMS DEPENDENCIES active_scaffold! byebug + cloudinary coffee-rails (~> 4.1.0) jbuilder (~> 2.0) jquery-rails diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb new file mode 100644 index 0000000..f5c0323 --- /dev/null +++ b/app/controllers/items_controller.rb @@ -0,0 +1,5 @@ +class ItemsController < ApplicationController + active_scaffold :"item" do |conf| + conf.columns[:unit].form_ui = :select + end +end diff --git a/app/controllers/media_types_controller.rb b/app/controllers/media_types_controller.rb new file mode 100644 index 0000000..0ba56d9 --- /dev/null +++ b/app/controllers/media_types_controller.rb @@ -0,0 +1,4 @@ +class MediaTypesController < ApplicationController + active_scaffold :"media_type" do |conf| + end +end diff --git a/app/controllers/multi_media_descriptions_controller.rb b/app/controllers/multi_media_descriptions_controller.rb new file mode 100644 index 0000000..5dc6da7 --- /dev/null +++ b/app/controllers/multi_media_descriptions_controller.rb @@ -0,0 +1,5 @@ +class MultiMediaDescriptionsController < ApplicationController + active_scaffold :"multi_media_description" do |conf| + conf.columns[:media_type].form_ui = :select + end +end diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb new file mode 100644 index 0000000..2557a50 --- /dev/null +++ b/app/controllers/units_controller.rb @@ -0,0 +1,4 @@ +class UnitsController < ApplicationController + active_scaffold :"unit" do |conf| + end +end diff --git a/app/helpers/items_helper.rb b/app/helpers/items_helper.rb new file mode 100644 index 0000000..f057aa6 --- /dev/null +++ b/app/helpers/items_helper.rb @@ -0,0 +1,4 @@ +module ItemsHelper + + +end \ No newline at end of file diff --git a/app/helpers/media_types_helper.rb b/app/helpers/media_types_helper.rb new file mode 100644 index 0000000..33340bf --- /dev/null +++ b/app/helpers/media_types_helper.rb @@ -0,0 +1,2 @@ +module MediaTypesHelper +end \ No newline at end of file diff --git a/app/helpers/multi_media_descriptions_helper.rb b/app/helpers/multi_media_descriptions_helper.rb new file mode 100644 index 0000000..4fdfa59 --- /dev/null +++ b/app/helpers/multi_media_descriptions_helper.rb @@ -0,0 +1,2 @@ +module MultiMediaDescriptionsHelper +end \ No newline at end of file diff --git a/app/helpers/units_helper.rb b/app/helpers/units_helper.rb new file mode 100644 index 0000000..fac199c --- /dev/null +++ b/app/helpers/units_helper.rb @@ -0,0 +1,2 @@ +module UnitsHelper +end \ No newline at end of file diff --git a/app/models/Category.rb b/app/models/Category.rb deleted file mode 100644 index 470d4db..0000000 --- a/app/models/Category.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Category < ActiveRecord::Base - has_many :sub_categories - belongs_to :section -end diff --git a/app/models/category.rb b/app/models/category.rb new file mode 100644 index 0000000..df3f6f4 --- /dev/null +++ b/app/models/category.rb @@ -0,0 +1,4 @@ +class Category < ActiveRecord::Base + has_many :sub_categories + belongs_to :section +end diff --git a/app/models/item.rb b/app/models/item.rb new file mode 100644 index 0000000..edcf40e --- /dev/null +++ b/app/models/item.rb @@ -0,0 +1,4 @@ +class Item < ActiveRecord::Base + belongs_to :unit + has_many :multi_media_descriptions +end diff --git a/app/models/media_type.rb b/app/models/media_type.rb new file mode 100644 index 0000000..97977ac --- /dev/null +++ b/app/models/media_type.rb @@ -0,0 +1,3 @@ +class MediaType < ActiveRecord::Base + has_many :multi_media_descriptions +end diff --git a/app/models/multi_media_description.rb b/app/models/multi_media_description.rb new file mode 100644 index 0000000..57f7a26 --- /dev/null +++ b/app/models/multi_media_description.rb @@ -0,0 +1,5 @@ +class MultiMediaDescription < ActiveRecord::Base + belongs_to :item + belongs_to :media_type + +end diff --git a/app/models/section.rb b/app/models/section.rb index 1582577..d255568 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -1,3 +1,3 @@ class Section < ActiveRecord::Base - has_many :categories + has_many :categories end diff --git a/app/models/unit.rb b/app/models/unit.rb new file mode 100644 index 0000000..ee09039 --- /dev/null +++ b/app/models/unit.rb @@ -0,0 +1,2 @@ +class Unit < ActiveRecord::Base +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index fb6ecab..44447a6 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,12 +1,19 @@ - Ribicabackoffice + Ribica Back Office <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> +
+ <%= link_to "Items", items_path %> + <%= link_to "Sections", sections_path %> + <%= link_to "Units", units_path %> + <%= link_to "Media Types", media_types_path %> +
+ <%= yield %> diff --git a/config/cloudinary.yml b/config/cloudinary.yml new file mode 100644 index 0000000..87b7603 --- /dev/null +++ b/config/cloudinary.yml @@ -0,0 +1,19 @@ +--- +development: + cloud_name: lfvt7ps2n + api_key: '128267513872316' + api_secret: OiLGZbAFd3vcY31ytuYlyBdIi9c + enhance_image_tag: true + static_image_support: false +production: + cloud_name: lfvt7ps2n + api_key: '128267513872316' + api_secret: OiLGZbAFd3vcY31ytuYlyBdIi9c + enhance_image_tag: true + static_image_support: true +test: + cloud_name: lfvt7ps2n + api_key: '128267513872316' + api_secret: OiLGZbAFd3vcY31ytuYlyBdIi9c + enhance_image_tag: true + static_image_support: false diff --git a/config/routes.rb b/config/routes.rb index 1972528..f3a1cd8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,17 @@ Rails.application.routes.draw do + + resources :multi_media_descriptions do as_routes end resources :sections do as_routes end + resources :media_types do as_routes end + resources :items do as_routes end + resources :units 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. # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" - # root 'welcome#index' + root 'items#index' # Example of regular route: # get 'products/:id' => 'catalog#view' diff --git a/test/controllers/items_controller_test.rb b/test/controllers/items_controller_test.rb new file mode 100644 index 0000000..29b7aeb --- /dev/null +++ b/test/controllers/items_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class ItemsControllerTest < ActionController::TestCase + setup do + @item = items(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:items) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create item" do + assert_difference('Item.count') do + post :create, item: { code: @item.code, current_input_price: @item.current_input_price, description: @item.description, list_price: @item.list_price, name: @item.name, on_display: @item.on_display, stock: @item.stock, sub_category_id: @item.sub_category_id, unit_id: @item.unit_id, units_in_pack: @item.units_in_pack } + end + + assert_redirected_to item_path(assigns(:item)) + end + + test "should show item" do + get :show, id: @item + assert_response :success + end + + test "should get edit" do + get :edit, id: @item + assert_response :success + end + + test "should update item" do + patch :update, id: @item, item: { code: @item.code, current_input_price: @item.current_input_price, description: @item.description, list_price: @item.list_price, name: @item.name, on_display: @item.on_display, stock: @item.stock, sub_category_id: @item.sub_category_id, unit_id: @item.unit_id, units_in_pack: @item.units_in_pack } + assert_redirected_to item_path(assigns(:item)) + end + + test "should destroy item" do + assert_difference('Item.count', -1) do + delete :destroy, id: @item + end + + assert_redirected_to items_path + end +end diff --git a/test/controllers/media_types_controller_test.rb b/test/controllers/media_types_controller_test.rb new file mode 100644 index 0000000..687377f --- /dev/null +++ b/test/controllers/media_types_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class MediaTypesControllerTest < ActionController::TestCase + setup do + @media_type = media_types(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:media_types) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create media_type" do + assert_difference('MediaType.count') do + post :create, media_type: { name: @media_type.name } + end + + assert_redirected_to media_type_path(assigns(:media_type)) + end + + test "should show media_type" do + get :show, id: @media_type + assert_response :success + end + + test "should get edit" do + get :edit, id: @media_type + assert_response :success + end + + test "should update media_type" do + patch :update, id: @media_type, media_type: { name: @media_type.name } + assert_redirected_to media_type_path(assigns(:media_type)) + end + + test "should destroy media_type" do + assert_difference('MediaType.count', -1) do + delete :destroy, id: @media_type + end + + assert_redirected_to media_types_path + end +end diff --git a/test/controllers/multi_media_descriptions_controller_test.rb b/test/controllers/multi_media_descriptions_controller_test.rb new file mode 100644 index 0000000..3844a44 --- /dev/null +++ b/test/controllers/multi_media_descriptions_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class MultiMediaDescriptionsControllerTest < ActionController::TestCase + setup do + @multi_media_description = multi_media_descriptions(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:multi_media_descriptions) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create multi_media_description" do + assert_difference('MultiMediaDescription.count') do + post :create, multi_media_description: { item_id: @multi_media_description.item_id, media_type_id: @multi_media_description.media_type_id, url: @multi_media_description.url } + end + + assert_redirected_to multi_media_description_path(assigns(:multi_media_description)) + end + + test "should show multi_media_description" do + get :show, id: @multi_media_description + assert_response :success + end + + test "should get edit" do + get :edit, id: @multi_media_description + assert_response :success + end + + test "should update multi_media_description" do + patch :update, id: @multi_media_description, multi_media_description: { item_id: @multi_media_description.item_id, media_type_id: @multi_media_description.media_type_id, url: @multi_media_description.url } + assert_redirected_to multi_media_description_path(assigns(:multi_media_description)) + end + + test "should destroy multi_media_description" do + assert_difference('MultiMediaDescription.count', -1) do + delete :destroy, id: @multi_media_description + end + + assert_redirected_to multi_media_descriptions_path + end +end diff --git a/test/controllers/units_controller_test.rb b/test/controllers/units_controller_test.rb new file mode 100644 index 0000000..f9d8472 --- /dev/null +++ b/test/controllers/units_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class UnitsControllerTest < ActionController::TestCase + setup do + @unit = units(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:units) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create unit" do + assert_difference('Unit.count') do + post :create, unit: { name: @unit.name, short_name: @unit.short_name } + end + + assert_redirected_to unit_path(assigns(:unit)) + end + + test "should show unit" do + get :show, id: @unit + assert_response :success + end + + test "should get edit" do + get :edit, id: @unit + assert_response :success + end + + test "should update unit" do + patch :update, id: @unit, unit: { name: @unit.name, short_name: @unit.short_name } + assert_redirected_to unit_path(assigns(:unit)) + end + + test "should destroy unit" do + assert_difference('Unit.count', -1) do + delete :destroy, id: @unit + end + + assert_redirected_to units_path + end +end diff --git a/test/fixtures/items.yml b/test/fixtures/items.yml new file mode 100644 index 0000000..bfb9758 --- /dev/null +++ b/test/fixtures/items.yml @@ -0,0 +1,25 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + code: MyString + current_input_price: 9.99 + list_price: 9.99 + unit_id: 1 + units_in_pack: 9.99 + description: MyText + sub_category_id: 1 + stock: 1 + on_display: false + +two: + name: MyString + code: MyString + current_input_price: 9.99 + list_price: 9.99 + unit_id: 1 + units_in_pack: 9.99 + description: MyText + sub_category_id: 1 + stock: 1 + on_display: false diff --git a/test/fixtures/media_types.yml b/test/fixtures/media_types.yml new file mode 100644 index 0000000..56066c6 --- /dev/null +++ b/test/fixtures/media_types.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/fixtures/multi_media_descriptions.yml b/test/fixtures/multi_media_descriptions.yml new file mode 100644 index 0000000..88b80fa --- /dev/null +++ b/test/fixtures/multi_media_descriptions.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + url: MyString + item_id: 1 + media_type_id: 1 + +two: + url: MyString + item_id: 1 + media_type_id: 1 diff --git a/test/fixtures/units.yml b/test/fixtures/units.yml new file mode 100644 index 0000000..e356db0 --- /dev/null +++ b/test/fixtures/units.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + short_name: MyString + +two: + name: MyString + short_name: MyString diff --git a/test/models/item_test.rb b/test/models/item_test.rb new file mode 100644 index 0000000..f564d81 --- /dev/null +++ b/test/models/item_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ItemTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/media_type_test.rb b/test/models/media_type_test.rb new file mode 100644 index 0000000..66245a2 --- /dev/null +++ b/test/models/media_type_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MediaTypeTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/multi_media_description_test.rb b/test/models/multi_media_description_test.rb new file mode 100644 index 0000000..8dda12d --- /dev/null +++ b/test/models/multi_media_description_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MultiMediaDescriptionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/unit_test.rb b/test/models/unit_test.rb new file mode 100644 index 0000000..a819877 --- /dev/null +++ b/test/models/unit_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UnitTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end