mechanize_store 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/mechanize_store/product_categories_controller.rb +1 -1
- data/app/controllers/mechanize_store/product_sections_controller.rb +77 -0
- data/app/models/mechanize_store/product_category.rb +3 -4
- data/app/models/mechanize_store/product_section.rb +18 -0
- data/app/views/mechanize_store/product_sections/_form.html.erb +11 -0
- data/app/views/mechanize_store/product_sections/edit.html.erb +12 -0
- data/app/views/mechanize_store/product_sections/index.html.erb +46 -0
- data/app/views/mechanize_store/product_sections/new.html.erb +9 -0
- data/app/views/mechanize_store/product_sections/show.html.erb +15 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20140606123953_create_mechanize_store_product_sections.rb +9 -0
- data/db/migrate/20140606124916_add_slug_to_product_section.rb +5 -0
- data/db/migrate/20140606130912_add_product_section_id_to_mechanize_store_product_category.rb +5 -0
- data/lib/mechanize_store/version.rb +1 -1
- data/spec/controllers/mechanize_store/product_sections_controller_spec.rb +139 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +9 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +16 -0
- data/spec/dummy/log/test.log +8397 -0
- data/spec/dummy/public/photos/1/medium.png +0 -0
- data/spec/dummy/public/photos/1/thumb.png +0 -0
- data/spec/factories/mechanize_store_product_categories.rb +1 -1
- data/spec/factories/mechanize_store_product_sections.rb +7 -0
- data/spec/models/mechanize_store/product_section_spec.rb +7 -0
- data/spec/routing/{store → mechanize_store}/flags_routing_spec.rb +0 -0
- data/spec/routing/{store → mechanize_store}/orders_routing_spec.rb +0 -0
- data/spec/routing/{store → mechanize_store}/product_categories_routing_spec.rb +0 -0
- data/spec/routing/mechanize_store/product_sections_routing_spec.rb +39 -0
- data/spec/routing/{store → mechanize_store}/products_photos_routing_spec.rb +0 -0
- data/spec/routing/{store → mechanize_store}/products_routing_spec.rb +0 -0
- metadata +30 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6415f245e948dd67bac6d233a7770d99d1061110
|
4
|
+
data.tar.gz: 1d7eb57d6217200f37815044c1e0d0d61209be33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98dc4f19e355cd9787915d42245e2efe3427d4d6b7a25f9cad27d27bd8b323db2996a7c460aa94032f8a5b61a5e4e69b320d4fabbca7e401c887e68b43395f22
|
7
|
+
data.tar.gz: 03773d34fff8898e05985e7248516b862a07c918f6e4b24e0b3ae9288dc8bcd339aa32b24811f754746743618d270dd58f843274c22e1c9e147c242e14c529ca
|
@@ -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 :
|
4
|
-
|
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,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,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
@@ -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
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -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:
|
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"
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -25624,3 +25624,19 @@ Migrating to AddSlugToProductCategory (20140605213358)
|
|
25624
25624
|
[1m[36m (0.2ms)[0m [1mALTER TABLE "product_categories" ADD "slug" varchar(255)[0m
|
25625
25625
|
SQLite3::SQLException: no such table: product_categories: ALTER TABLE "product_categories" ADD "slug" varchar(255)
|
25626
25626
|
[1m[35m (0.0ms)[0m rollback transaction
|
25627
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
25628
|
+
Migrating to AddSlugToProductCategory (20140605213358)
|
25629
|
+
[1m[35m (0.1ms)[0m begin transaction
|
25630
|
+
[1m[36m (0.7ms)[0m [1mALTER TABLE "mechanize_store_product_categories" ADD "slug" varchar(255)[0m
|
25631
|
+
[1m[35mSQL (0.5ms)[0m INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20140605213358"]]
|
25632
|
+
[1m[36m (3.1ms)[0m [1mcommit transaction[0m
|
25633
|
+
Migrating to CreateMechanizeStoreProductSections (20140606123953)
|
25634
|
+
[1m[35m (0.1ms)[0m begin transaction
|
25635
|
+
[1m[36m (0.4ms)[0m [1mCREATE TABLE "mechanize_store_product_sections" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "created_at" datetime, "updated_at" datetime) [0m
|
25636
|
+
[1m[35mSQL (0.1ms)[0m INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20140606123953"]]
|
25637
|
+
[1m[36m (0.7ms)[0m [1mcommit transaction[0m
|
25638
|
+
Migrating to AddSlugToProductSection (20140606124916)
|
25639
|
+
[1m[35m (0.1ms)[0m begin transaction
|
25640
|
+
[1m[36m (0.2ms)[0m [1mALTER TABLE "product_sections" ADD "slug" varchar(255)[0m
|
25641
|
+
SQLite3::SQLException: no such table: product_sections: ALTER TABLE "product_sections" ADD "slug" varchar(255)
|
25642
|
+
[1m[35m (0.0ms)[0m rollback transaction
|