public
Description: Pretty url support for Ruby on Rails applications
Homepage: http://www.caring.com
Clone URL: git://github.com/caring/acts_as_url_param.git
Fixed acts_as_url_param bug where hidden & deleted items url_names were 
not being accounted for
joshuabates (author)
Fri Feb 08 15:50:22 -0800 2008
commit  fea3672132b003568a04cbe6005e639f243286be
tree    6b9e9f878ffea8f9049053abd05b6066a5c64805
parent  917a24365a3935446f9e26f1eea9e01a85208e4c
...
113
114
115
116
117
118
119
 
 
 
 
 
 
120
121
122
...
160
161
162
 
163
164
165
...
113
114
115
 
 
 
 
116
117
118
119
120
121
122
123
124
...
162
163
164
165
166
167
168
0
@@ -113,10 +113,12 @@ module ActsAsUrlParam
0
     
0
     module ClassMethods
0
       def url_param_available?(candidate, id=nil)
0
- if proc = acts_as_url_options[:block]
0
- !(proc.arity == 1 ? proc.call(candidate) : proc.call(candidate, id))
0
- else
0
- url_param_available_for_model?(candidate, id)
0
+ Caring::Scope::State.instance.with_admin_scope(true) do
0
+ if proc = acts_as_url_options[:block]
0
+ !(proc.arity == 1 ? proc.call(candidate) : proc.call(candidate, id))
0
+ else
0
+ url_param_available_for_model?(candidate, id)
0
+ end
0
         end
0
       end
0
       
0
@@ -160,6 +162,7 @@ module ActsAsUrlParam
0
       
0
       def set_url_param
0
         if url_param.blank? or (acts_as_url_options[:on] != :create && !@url_name_manually_set)
0
+ send(acts_as_url_options[:before]) if acts_as_url_options[:before]
0
           url = compute_url_param
0
           send("#{acts_as_url_options[:column]}=", url) unless url.blank?
0
           @url_name_manually_set = false
...
10
11
12
 
13
14
15
...
150
151
152
 
 
 
 
 
 
 
 
153
154
155
...
167
168
169
 
 
 
 
 
 
 
 
 
 
170
171
172
...
10
11
12
13
14
15
16
...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
...
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
0
@@ -10,6 +10,7 @@ require "magazine"
0
 require "newspaper"
0
 require "user"
0
 require "story"
0
+require "before_item"
0
 
0
 class ActsAsUrlParamTest < Test::Unit::TestCase
0
   
0
@@ -150,6 +151,14 @@ class ActsAsUrlParamTest < Test::Unit::TestCase
0
     assert_equal(item_url, item.to_param)
0
   end
0
   
0
+ def test_should_work_with_two_items_of_same_name
0
+ name = "just another name"
0
+ item = ActsAsUrlParam::Item.create(:name => name)
0
+ url = item.to_param
0
+ item.update_attributes(:content => "irrelevant")
0
+ assert_equal url, item.to_param
0
+ end
0
+
0
   def test_should_work_with_sti
0
     item = ActsAsUrlParam::Item.create(:name => 'an item')
0
     book = ActsAsUrlParam::Book.create(:name => 'an item')
0
@@ -167,6 +176,16 @@ class ActsAsUrlParamTest < Test::Unit::TestCase
0
     assert !magazine.to_param.blank?
0
   end
0
   
0
+ def test_should_run_before_method_if_passed
0
+ ActsAsUrlParam::BeforeItem.any_instance.expects(:set_name)
0
+ item = ActsAsUrlParam::BeforeItem.create(:name => 'the name')
0
+ end
0
+
0
+ def test_should_run_before_method_before_setting_url
0
+ item = ActsAsUrlParam::BeforeItem.create(:name => 'the name')
0
+ assert_match /is-set/, item.to_param
0
+ end
0
+
0
   private
0
   def acts_as_url_name_model(column = nil, options = {})
0
     m = Class.new(ActiveRecord::Base)
...
12
13
14
 
15
16
17
...
12
13
14
15
16
17
18
0
@@ -12,6 +12,7 @@ ActiveRecord::Schema.define() do
0
   
0
   create_table :items do |t|
0
     t.column :name, :string
0
+ t.column :content, :string
0
     t.column :type, :string, :default => 'Item', :null => false
0
     t.column :url_name, :string
0
   end

Comments

    No one has commented yet.