My favorites
▼
|
Sign in
substruct
Open-source Ruby on Rails E-Commerce
Project Home
Downloads
Wiki
Issues
Source
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
162
attachment: allow_same_named_tags.diff
(6.3 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
Index: plugins/substruct/test/unit/tag_test.rb
===================================================================
--- plugins/substruct/test/unit/tag_test.rb (revision 177)
+++ plugins/substruct/test/unit/tag_test.rb (working copy)
@@ -45,12 +45,11 @@
assert a_tag.errors.invalid?(:name)
# A tag must have a name.
assert_equal "can't be blank", a_tag.errors.on(:name)
+
+ # Duplicate tag names are ok
a_tag.name = "Books"
- assert !a_tag.valid?
- assert a_tag.errors.invalid?(:name)
- # A tag must have an unique name.
- assert_equal "has already been taken", a_tag.errors.on(:name)
- assert !a_tag.save
+ assert a_tag.valid?
+ assert a_tag.save
end
@@ -110,4 +109,4 @@
end
-end
\ No newline at end of file
+end
Index: plugins/substruct/test/functional/store_controller_test.rb
===================================================================
--- plugins/substruct/test/functional/store_controller_test.rb (revision 177)
+++ plugins/substruct/test/functional/store_controller_test.rb (working copy)
@@ -65,7 +65,7 @@
# Now call it again with a tag.
a_tag = tags(:weapons)
- get :show_by_tags, :tags => [a_tag.name]
+ get :show_by_tags, :tags => [a_tag.name_and_id]
assert_response :success
assert_equal "Store #{assigns(:viewing_tags).collect { |t| ' > ' + t.name}}", assigns(:title)
assert assigns(:products)
@@ -74,7 +74,7 @@
# Now call it again with a tag and a subtag.
a_tag = tags(:weapons)
a_subtag = tags(:mass_destruction)
- get :show_by_tags, :tags => [a_tag.name, a_subtag.name]
+ get :show_by_tags, :tags => [a_tag.name_and_id, a_subtag.name_and_id]
assert_response :success
assert_equal "Store #{assigns(:viewing_tags).collect { |t| ' > ' + t.name}}", assigns(:title)
assert assigns(:products)
@@ -84,8 +84,16 @@
get :show_by_tags, :tags => ["invalid"]
assert_response :missing
+ # Call it with an invalid tag/ID combo
+ get :show_by_tags, :tags => ["#{a_tag.name}_999999"]
+ assert_response :missing
+
+ # Call it with a mismatched tag/ID combo
+ get :show_by_tags, :tags => ["#{a_tag.name}_#{a_tag.id+1}"]
+ assert_response :missing
+
# Call it again with an invalid child tag.
- get :show_by_tags, :tags => [a_tag.name, "invalid"]
+ get :show_by_tags, :tags => [a_tag.name_and_id, "invalid"]
assert_response :missing
end
Index: plugins/substruct/app/models/tag.rb
===================================================================
--- plugins/substruct/app/models/tag.rb (revision 177)
+++ plugins/substruct/app/models/tag.rb (working copy)
@@ -8,7 +8,6 @@
has_and_belongs_to_many :products,
:join_table => 'products_tags'
validates_presence_of :name
- validates_uniqueness_of :name
acts_as_tree :order => '-rank DESC'
# Most used finder function for tags.
@@ -58,4 +57,9 @@
def product_count
@cached_product_count ||= self.products.count
end
-end
\ No newline at end of file
+
+ def name_and_id
+ "#{self.name}_#{self.id}"
+ end
+
+end
Index: plugins/substruct/app/controllers/store_controller.rb
===================================================================
--- plugins/substruct/app/controllers/store_controller.rb (revision 177)
+++ plugins/substruct/app/controllers/store_controller.rb (working copy)
@@ -72,24 +72,35 @@
def show_by_tags
# Tags are passed in as an array.
# Passed into this controller like this:
- # /store/show_by_tags/tag_one/tag_two/tag_three/...
- @tag_names = params[:tags]
- # Generate tag ID list from names
- tag_ids_array = Array.new
- for name in @tag_names
- temp_tag = Tag.find_by_name(name)
- if temp_tag then
- tag_ids_array << temp_tag.id
- else
- render(:file => 'public/404.html', :status => 404) and return
- end
+ # /store/show_by_tags/tag_one_id/tag_two_id/tag_three_id/...
+ # like
+ # /store/show_by_tags/clothes_3/hats_4/shoes_5
+ @tag_names = params[:tags].collect{|tag_and_name| tag_and_name =~ /^(.*)_\d+$/; $1}
+ tag_ids_array = params[:tags].collect{|tag_and_name| tag_and_name =~ /^.*_(\d+)$/; $1}
+
+ # Double check they're all legit tags
+ tag_ids_array.each_with_index do |id, index|
+ if(id.blank?)
+ render(:file => 'public/404.html', :status => 404) and return
+ end
+ begin
+ temp_tag = Tag.find id
+ if !temp_tag then
+ raise 'not found!'
+ end
+ if temp_tag.name != @tag_names[index]
+ raise 'mismatched name/id'
+ end
+ rescue Exception
+ render(:file => 'public/404.html', :status => 404) and return
+ end
end
if tag_ids_array.size == 0
render(:file => 'public/404.html', :status => 404) and return
end
- @viewing_tags = Tag.find(tag_ids_array, :order => "parent_id ASC")
+ @viewing_tags = Tag.find(tag_ids_array, :order => "parent_id ASC")
viewing_tag_names = @viewing_tags.collect { |t| " > #{t.name}"}
@title = "Store #{viewing_tag_names}"
@tags = Tag.find_related_tags(tag_ids_array)
Index: plugins/substruct/app/views/layouts/main.rhtml
===================================================================
--- plugins/substruct/app/views/layouts/main.rhtml (revision 177)
+++ plugins/substruct/app/views/layouts/main.rhtml (working copy)
@@ -74,7 +74,7 @@
tag.name,
:controller => 'store',
:action => 'show_by_tags',
- :tags => [tag.name]
+ :tags => [tag.name_and_id]
)
%>
</li>
@@ -94,7 +94,7 @@
tag.name,
:controller => 'store',
:action => 'show_by_tags',
- :tags => [@main_tag_active.name, tag.name]
+ :tags => [@main_tag_active.name_and_id, tag.name_and_id]
)
%>
</li>
Index: plugins/substruct/app/views/store/_tag_link.rhtml
===================================================================
--- plugins/substruct/app/views/store/_tag_link.rhtml (revision 177)
+++ plugins/substruct/app/views/store/_tag_link.rhtml (working copy)
@@ -3,9 +3,9 @@
# our tag breadcrumb navigation.
if tag_names then
link_to_tags = tag_names.clone
- link_to_tags << tag_link.name
+ link_to_tags << tag_link.name_and_id
else
- link_to_tags = tag_link.name
+ link_to_tags = tag_link.name_and_id
end
%>
<%= link_to h(tag_link.name), :controller => 'store', :action => 'show_by_tags', :tags => link_to_tags %>
Powered by
Google Project Hosting