mechanize_store 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/mechanize_store/product_categories_controller.rb +1 -1
  3. data/app/controllers/mechanize_store/product_sections_controller.rb +77 -0
  4. data/app/models/mechanize_store/product_category.rb +3 -4
  5. data/app/models/mechanize_store/product_section.rb +18 -0
  6. data/app/views/mechanize_store/product_sections/_form.html.erb +11 -0
  7. data/app/views/mechanize_store/product_sections/edit.html.erb +12 -0
  8. data/app/views/mechanize_store/product_sections/index.html.erb +46 -0
  9. data/app/views/mechanize_store/product_sections/new.html.erb +9 -0
  10. data/app/views/mechanize_store/product_sections/show.html.erb +15 -0
  11. data/config/routes.rb +2 -0
  12. data/db/migrate/20140606123953_create_mechanize_store_product_sections.rb +9 -0
  13. data/db/migrate/20140606124916_add_slug_to_product_section.rb +5 -0
  14. data/db/migrate/20140606130912_add_product_section_id_to_mechanize_store_product_category.rb +5 -0
  15. data/lib/mechanize_store/version.rb +1 -1
  16. data/spec/controllers/mechanize_store/product_sections_controller_spec.rb +139 -0
  17. data/spec/dummy/db/development.sqlite3 +0 -0
  18. data/spec/dummy/db/schema.rb +9 -1
  19. data/spec/dummy/db/test.sqlite3 +0 -0
  20. data/spec/dummy/log/development.log +16 -0
  21. data/spec/dummy/log/test.log +8397 -0
  22. data/spec/dummy/public/photos/1/medium.png +0 -0
  23. data/spec/dummy/public/photos/1/thumb.png +0 -0
  24. data/spec/factories/mechanize_store_product_categories.rb +1 -1
  25. data/spec/factories/mechanize_store_product_sections.rb +7 -0
  26. data/spec/models/mechanize_store/product_section_spec.rb +7 -0
  27. data/spec/routing/{store → mechanize_store}/flags_routing_spec.rb +0 -0
  28. data/spec/routing/{store → mechanize_store}/orders_routing_spec.rb +0 -0
  29. data/spec/routing/{store → mechanize_store}/product_categories_routing_spec.rb +0 -0
  30. data/spec/routing/mechanize_store/product_sections_routing_spec.rb +39 -0
  31. data/spec/routing/{store → mechanize_store}/products_photos_routing_spec.rb +0 -0
  32. data/spec/routing/{store → mechanize_store}/products_routing_spec.rb +0 -0
  33. metadata +30 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6cf4510b4cc07bf1463193454f45d617e142ef3
4
- data.tar.gz: bde6347aca75f4b9040f3a5db456b8b2844bb3cb
3
+ metadata.gz: 6415f245e948dd67bac6d233a7770d99d1061110
4
+ data.tar.gz: 1d7eb57d6217200f37815044c1e0d0d61209be33
5
5
  SHA512:
6
- metadata.gz: 974bc6f020e273d2f369d13b84144c4e3dce8dc92cea6c13197a57ebba3f272a6a28b31388c316325833ca00a80ec93d2736fe4b6329a4dd8e76be0c011f64a6
7
- data.tar.gz: b1991b66f17011754b88eafbe8c12aeec9ced472a97358944a34d24b48724fb93c3555ed1dd6620a25feb9d2d381439d066b0ff4b159abf3f77701445af4c321
6
+ metadata.gz: 98dc4f19e355cd9787915d42245e2efe3427d4d6b7a25f9cad27d27bd8b323db2996a7c460aa94032f8a5b61a5e4e69b320d4fabbca7e401c887e68b43395f22
7
+ data.tar.gz: 03773d34fff8898e05985e7248516b862a07c918f6e4b24e0b3ae9288dc8bcd339aa32b24811f754746743618d270dd58f843274c22e1c9e147c242e14c529ca
@@ -5,7 +5,7 @@ module MechanizeStore
5
5
  respond_to :html, :json, :xml
6
6
 
7
7
  def index
8
- @search = ProductCategory.orphans.search(params[:q])
8
+ @search = ProductCategory.search(params[:q])
9
9
 
10
10
  @product_categories = @search.result.paginate(page: params[:page])
11
11
 
@@ -0,0 +1,77 @@
1
+ module MechanizeStore
2
+ class ProductSectionsController < ApplicationController
3
+ before_action :set_product_section, only: [:show, :edit, :update, :destroy]
4
+
5
+ respond_to :html, :json, :xml
6
+
7
+ def index
8
+ @search = ProductSection.search(params[:q])
9
+
10
+ @product_sections = @search.result.paginate(page: params[:page])
11
+
12
+ respond_with @product_sections
13
+ end
14
+
15
+ def show
16
+ respond_with @product_section
17
+ end
18
+
19
+ def new
20
+ @product_section = ProductSection.new
21
+ respond_with @product_section
22
+ end
23
+
24
+ def edit
25
+ respond_with @product_section
26
+ end
27
+
28
+ def create
29
+ @product_section = ProductSection.new(product_section_params)
30
+
31
+ respond_with @product_section do |format|
32
+ if @product_section.save
33
+ format.html do
34
+ flash[:notice] = I18n.t(:created, model: I18n.t(:product_section, scope: "activerecord.models"))
35
+ redirect_to @product_section
36
+ end
37
+ else
38
+ format.html { render action: "new" }
39
+ end
40
+ end
41
+ end
42
+
43
+ def update
44
+ @product_section = ProductSection.find(params[:id])
45
+
46
+ respond_with @product_section do |format|
47
+ if @product_section.update(product_section_params)
48
+ format.html do
49
+ flash[:notice] = I18n.t(:updated, model: I18n.t(:product_section, scope: "activerecord.models"))
50
+ redirect_to @product_section
51
+ end
52
+ else
53
+ format.html { render action: "edit" }
54
+ end
55
+ end
56
+ end
57
+
58
+ def destroy
59
+ @product_section = ProductSection.find(params[:id])
60
+
61
+ flash[:alert] = I18n.t(:removed, model: I18n.t(:product_section, scope: "activerecord.models")) if @product_section.destroy
62
+
63
+ respond_with @product_section, :location => product_sections_url
64
+ end
65
+
66
+ private
67
+ # Use callbacks to share common setup or constraints between actions.
68
+ def set_product_section
69
+ @product_section = ProductSection.find(params[:id])
70
+ end
71
+
72
+ # Only allow a trusted parameter "white list" through.
73
+ def product_section_params
74
+ params.require(:product_section).permit(:name)
75
+ end
76
+ end
77
+ end
@@ -1,12 +1,11 @@
1
1
  module MechanizeStore
2
2
  class ProductCategory < ActiveRecord::Base
3
- belongs_to :product_category, class_name: MechanizeStore::ProductCategory
4
- has_many :product_categories
3
+ belongs_to :product_section
4
+
5
+ has_many :products
5
6
 
6
7
  validates :name, presence: true
7
8
 
8
- scope :orphans, -> { where("product_category_id is NULL") }
9
-
10
9
  after_create :create_slug
11
10
  before_update :set_defaults
12
11
 
@@ -0,0 +1,18 @@
1
+ module MechanizeStore
2
+ class ProductSection < ActiveRecord::Base
3
+ has_many :product_categories
4
+
5
+ has_many :products, through: :product_categories
6
+
7
+ after_create :create_slug
8
+ before_update :set_defaults
9
+
10
+ def set_defaults
11
+ self.slug = self.name.parameterize
12
+ end
13
+
14
+ def create_slug
15
+ self.update_attributes(:slug => self.name.parameterize)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ <%= simple_form_for(@product_section) do |f| %>
2
+ <%= f.error_notification %>
3
+
4
+ <div class="form-group">
5
+ <%= f.input :name %>
6
+ </div>
7
+
8
+ <div class="form-actions">
9
+ <%= f.button :submit, class: "btn btn-primary" %>
10
+ </div>
11
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <%= title t(:editing, model: t("product_section", scope: "activerecord.models")) %>
2
+
3
+ <% content_for :right do -%>
4
+ <li class="active">
5
+ <%= link_to t(:details), @product_section %>
6
+ </li>
7
+ <li class="active">
8
+ <%= link_to t(:back), product_sections_path %>
9
+ </li>
10
+ <% end -%>
11
+
12
+ <%= render 'form' %>
@@ -0,0 +1,46 @@
1
+ <%= title t("product_section", scope: "activerecord.models").pluralize %>
2
+
3
+ <% content_for :right do -%>
4
+ <li class="active">
5
+ <%= link_to t("new_product_section"), new_product_section_path %>
6
+ </li>
7
+ <% end -%>
8
+
9
+ <table class="table table-striped">
10
+ <thead>
11
+ <tr>
12
+ <th><%= sort_link @search, :id, t(:id, scope: "activerecord.attributes") %></th>
13
+ <th><%= sort_link @search, :name, t(:name, scope: "activerecord.attributes.product_section") %></th>
14
+ <th colspan="3"></th>
15
+ </tr>
16
+ </thead>
17
+
18
+ <tbody>
19
+
20
+ <% @product_sections.each do |product_section| %>
21
+ <tr>
22
+ <td><%= product_section.id %></td>
23
+ <td><%= product_section.name %></td>
24
+ <td>
25
+ <%= link_to product_section do %>
26
+ <i class="fa fa-file"></i>
27
+ <% end -%>
28
+ </td>
29
+ <td>
30
+ <%= link_to edit_product_section_path(product_section) do %>
31
+ <i class="fa fa-edit"></i>
32
+ <% end -%>
33
+ </td>
34
+ <td>
35
+ <%= link_to product_section, method: :delete, data: { confirm: t(:are_you_sure) } do %>
36
+ <i class="fa fa-trash"></i>
37
+ <% end -%>
38
+ </td>
39
+ </tr>
40
+ <% end %>
41
+ </tbody>
42
+ </table>
43
+
44
+ <br>
45
+
46
+ <%= will_paginate @product_sections %>
@@ -0,0 +1,9 @@
1
+ <%= title t("new_product_section") %>
2
+
3
+ <% content_for :right do -%>
4
+ <li class="active">
5
+ <%= link_to t(:back), product_sections_path %>
6
+ </li>
7
+ <% end -%>
8
+
9
+ <%= render 'form' %>
@@ -0,0 +1,15 @@
1
+ <%= title t("product_section") %>
2
+
3
+ <% content_for :right do -%>
4
+ <li class="active">
5
+ <%= link_to t(:edit), edit_product_section_path(@product_section) %>
6
+ </li>
7
+ <li class="active">
8
+ <%= link_to t(:back), product_sections_path %>
9
+ </li>
10
+ <% end -%>
11
+
12
+ <p>
13
+ <small><%= t(:name, scope: "activerecord.attributes.product_section") %>:</small>
14
+ <h3><%= @product_section.name %></h3>
15
+ </p>
data/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  MechanizeStore::Engine.routes.draw do
2
+
3
+ resources :product_sections
2
4
  resources :product_categories
3
5
  resources :products do
4
6
  resources :product_photos, shallow: true
@@ -0,0 +1,9 @@
1
+ class CreateMechanizeStoreProductSections < ActiveRecord::Migration
2
+ def change
3
+ create_table :mechanize_store_product_sections do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class AddSlugToProductSection < ActiveRecord::Migration
2
+ def change
3
+ add_column :mechanize_store_product_sections, :slug, :string, index: true
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddProductSectionIdToMechanizeStoreProductCategory < ActiveRecord::Migration
2
+ def change
3
+ add_column :mechanize_store_product_categories, :product_section_id, :integer, index: true
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module MechanizeStore
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
@@ -0,0 +1,139 @@
1
+ require 'spec_helper'
2
+
3
+ module MechanizeStore
4
+ describe ProductSectionsController do
5
+
6
+ routes { MechanizeStore::Engine.routes }
7
+
8
+ let(:valid_attributes) { { "name" => "MyString" } }
9
+ let(:valid_session) { {} }
10
+
11
+ describe "GET index" do
12
+ it "assigns all product_sections as @product_sections" do
13
+ product_section = ProductSection.create! valid_attributes
14
+ get :index, {}, valid_session
15
+ assigns(:product_sections).should eq([product_section])
16
+ end
17
+ end
18
+
19
+ describe "GET show" do
20
+ it "assigns the requested product_section as @product_section" do
21
+ product_section = ProductSection.create! valid_attributes
22
+ get :show, {:id => product_section.to_param}, valid_session
23
+ assigns(:product_section).should eq(product_section)
24
+ end
25
+ end
26
+
27
+ describe "GET new" do
28
+ it "assigns a new product_section as @product_section" do
29
+ get :new, {}, valid_session
30
+ assigns(:product_section).should be_a_new(ProductSection)
31
+ end
32
+ end
33
+
34
+ describe "GET edit" do
35
+ it "assigns the requested product_section as @product_section" do
36
+ product_section = ProductSection.create! valid_attributes
37
+ get :edit, {:id => product_section.to_param}, valid_session
38
+ assigns(:product_section).should eq(product_section)
39
+ end
40
+ end
41
+
42
+ describe "POST create" do
43
+ describe "with valid params" do
44
+ it "creates a new ProductSection" do
45
+ expect {
46
+ post :create, {:product_section => valid_attributes}, valid_session
47
+ }.to change(ProductSection, :count).by(1)
48
+ end
49
+
50
+ it "assigns a newly created product_section as @product_section" do
51
+ post :create, {:product_section => valid_attributes}, valid_session
52
+ assigns(:product_section).should be_a(ProductSection)
53
+ assigns(:product_section).should be_persisted
54
+ end
55
+
56
+ it "redirects to the created product_section" do
57
+ post :create, {:product_section => valid_attributes}, valid_session
58
+ response.should redirect_to(ProductSection.last)
59
+ end
60
+ end
61
+
62
+ describe "with invalid params" do
63
+ it "assigns a newly created but unsaved product_section as @product_section" do
64
+ # Trigger the behavior that occurs when invalid params are submitted
65
+ ProductSection.any_instance.stub(:save).and_return(false)
66
+ post :create, {:product_section => { "name" => "invalid value" }}, valid_session
67
+ assigns(:product_section).should be_a_new(ProductSection)
68
+ end
69
+
70
+ it "re-renders the 'new' template" do
71
+ # Trigger the behavior that occurs when invalid params are submitted
72
+ ProductSection.any_instance.stub(:save).and_return(false)
73
+ post :create, {:product_section => { "name" => "invalid value" }}, valid_session
74
+ response.should render_template("new")
75
+ end
76
+ end
77
+ end
78
+
79
+ describe "PUT update" do
80
+ describe "with valid params" do
81
+ it "updates the requested product_section" do
82
+ product_section = ProductSection.create! valid_attributes
83
+ # Assuming there are no other product_sections in the database, this
84
+ # specifies that the ProductSection created on the previous line
85
+ # receives the :update_attributes message with whatever params are
86
+ # submitted in the request.
87
+ ProductSection.any_instance.should_receive(:update).with({ "name" => "MyString" })
88
+ put :update, {:id => product_section.to_param, :product_section => { "name" => "MyString" }}, valid_session
89
+ end
90
+
91
+ it "assigns the requested product_section as @product_section" do
92
+ product_section = ProductSection.create! valid_attributes
93
+ put :update, {:id => product_section.to_param, :product_section => valid_attributes}, valid_session
94
+ assigns(:product_section).should eq(product_section)
95
+ end
96
+
97
+ it "redirects to the product_section" do
98
+ product_section = ProductSection.create! valid_attributes
99
+ put :update, {:id => product_section.to_param, :product_section => valid_attributes}, valid_session
100
+ response.should redirect_to(product_section)
101
+ end
102
+ end
103
+
104
+ describe "with invalid params" do
105
+ it "assigns the product_section as @product_section" do
106
+ product_section = ProductSection.create! valid_attributes
107
+ # Trigger the behavior that occurs when invalid params are submitted
108
+ ProductSection.any_instance.stub(:save).and_return(false)
109
+ put :update, {:id => product_section.to_param, :product_section => { "name" => "invalid value" }}, valid_session
110
+ assigns(:product_section).should eq(product_section)
111
+ end
112
+
113
+ it "re-renders the 'edit' template" do
114
+ product_section = ProductSection.create! valid_attributes
115
+ # Trigger the behavior that occurs when invalid params are submitted
116
+ ProductSection.any_instance.stub(:save).and_return(false)
117
+ put :update, {:id => product_section.to_param, :product_section => { "name" => "invalid value" }}, valid_session
118
+ response.should render_template("edit")
119
+ end
120
+ end
121
+ end
122
+
123
+ describe "DELETE destroy" do
124
+ it "destroys the requested product_section" do
125
+ product_section = ProductSection.create! valid_attributes
126
+ expect {
127
+ delete :destroy, {:id => product_section.to_param}, valid_session
128
+ }.to change(ProductSection, :count).by(-1)
129
+ end
130
+
131
+ it "redirects to the product_sections list" do
132
+ product_section = ProductSection.create! valid_attributes
133
+ delete :destroy, {:id => product_section.to_param}, valid_session
134
+ response.should redirect_to(product_sections_url)
135
+ end
136
+ end
137
+
138
+ end
139
+ end
Binary file
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20140605213358) do
14
+ ActiveRecord::Schema.define(version: 20140606130912) do
15
15
 
16
16
  create_table "mechanize_store_flags", force: true do |t|
17
17
  t.string "name"
@@ -77,6 +77,7 @@ ActiveRecord::Schema.define(version: 20140605213358) do
77
77
  t.datetime "created_at"
78
78
  t.datetime "updated_at"
79
79
  t.string "slug"
80
+ t.integer "product_section_id"
80
81
  end
81
82
 
82
83
  create_table "mechanize_store_product_photos", force: true do |t|
@@ -91,6 +92,13 @@ ActiveRecord::Schema.define(version: 20140605213358) do
91
92
 
92
93
  add_index "mechanize_store_product_photos", ["product_id"], name: "index_mechanize_store_product_photos_on_product_id"
93
94
 
95
+ create_table "mechanize_store_product_sections", force: true do |t|
96
+ t.string "name"
97
+ t.datetime "created_at"
98
+ t.datetime "updated_at"
99
+ t.string "slug"
100
+ end
101
+
94
102
  create_table "mechanize_store_products", force: true do |t|
95
103
  t.string "name"
96
104
  t.text "description"
Binary file
@@ -25624,3 +25624,19 @@ Migrating to AddSlugToProductCategory (20140605213358)
25624
25624
   (0.2ms) ALTER TABLE "product_categories" ADD "slug" varchar(255)
25625
25625
  SQLite3::SQLException: no such table: product_categories: ALTER TABLE "product_categories" ADD "slug" varchar(255)
25626
25626
   (0.0ms) rollback transaction
25627
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
25628
+ Migrating to AddSlugToProductCategory (20140605213358)
25629
+  (0.1ms) begin transaction
25630
+  (0.7ms) ALTER TABLE "mechanize_store_product_categories" ADD "slug" varchar(255)
25631
+ SQL (0.5ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20140605213358"]]
25632
+  (3.1ms) commit transaction
25633
+ Migrating to CreateMechanizeStoreProductSections (20140606123953)
25634
+  (0.1ms) begin transaction
25635
+  (0.4ms) CREATE TABLE "mechanize_store_product_sections" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime, "updated_at" datetime) 
25636
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20140606123953"]]
25637
+  (0.7ms) commit transaction
25638
+ Migrating to AddSlugToProductSection (20140606124916)
25639
+  (0.1ms) begin transaction
25640
+  (0.2ms) ALTER TABLE "product_sections" ADD "slug" varchar(255)
25641
+ SQLite3::SQLException: no such table: product_sections: ALTER TABLE "product_sections" ADD "slug" varchar(255)
25642
+  (0.0ms) rollback transaction