public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
update plugins

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2736 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Mon Feb 12 05:07:05 -0800 2007
commit  04b98f73086119779661e9b5a34da458297c7843
tree    1eb482c758fb85b797a49c02975b67294f71aed6
parent  d90a0d8f4d768ab974c43db19a2af73d2cacd288
...
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
0
@@ -1,3 +1,7 @@
0
+* (2 Feb 2007)
0
+
0
+Add support for custom primary keys [Jeff Dean]
0
+
0
 * (2 July 2006)
0
 
0
 Add paranoid delete_all implementation [Marshall Roch]
...
120
121
122
123
 
124
125
126
...
120
121
122
 
123
124
125
126
0
@@ -120,7 +120,7 @@ module Caboose #:nodoc:
0
 
0
         def destroy_without_callbacks
0
           unless new_record?
0
- self.class.update_all self.class.send(:sanitize_sql, ["#{self.class.deleted_attribute} = ?", self.class.send(:current_time)]), ["id = ?", id]
0
+ self.class.update_all self.class.send(:sanitize_sql, ["#{self.class.deleted_attribute} = ?", self.class.send(:current_time)]), ["#{self.class.primary_key} = ?", id]
0
           end
0
           freeze
0
         end
...
50
51
52
53
 
 
 
 
 
 
54
55
56
...
50
51
52
 
53
54
55
56
57
58
59
60
61
0
@@ -50,7 +50,12 @@ module Technoweenie # :nodoc:
0
         protected
0
           # Destroys the file. Called in the after_destroy callback
0
           def destroy_file
0
- FileUtils.rm full_filename rescue nil
0
+ FileUtils.rm full_filename
0
+ # remove directory also if it is now empty
0
+ Dir.rmdir(File.dirname(full_filename)) if (Dir.entries(File.dirname(full_filename))-['.','..']).empty?
0
+ rescue
0
+ logger.info "Exception destroying #{full_filename.inspect}: [#{$!.class.name}] #{$1.to_s}"
0
+ logger.warn $!.backtrace.collect { |b| " > #{b}" }.join("\n")
0
           end
0
 
0
           # Renames the given file before saving
...
157
158
159
160
 
161
162
163
164
165
 
166
167
168
169
 
170
171
172
173
 
174
175
176
...
251
252
253
254
 
255
256
257
258
 
259
260
261
262
 
263
264
265
...
157
158
159
 
160
161
162
163
164
 
165
166
167
168
 
169
170
171
172
 
173
174
175
176
...
251
252
253
 
254
255
256
257
 
258
259
260
261
 
262
263
264
265
0
@@ -157,20 +157,20 @@ module Technoweenie # :nodoc:
0
         end
0
         
0
         def self.port_string
0
- @port_string ||= options[:port] == (options[:use_ssl] ? 443 : 80) ? '' : ":#{options[:port]}"
0
+ @port_string ||= s3_config[:port] == (s3_config[:use_ssl] ? 443 : 80) ? '' : ":#{s3_config[:port]}"
0
         end
0
 
0
         module ClassMethods
0
           def s3_protocol
0
- Technoweenie::AttachmentFu::Backends::S3.protocol
0
+ Technoweenie::AttachmentFu::Backends::S3Backend.protocol
0
           end
0
           
0
           def s3_hostname
0
- Technoweenie::AttachmentFu::Backends::S3.hostname
0
+ Technoweenie::AttachmentFu::Backends::S3Backend.hostname
0
           end
0
           
0
           def s3_port_string
0
- Technoweenie::AttachmentFu::Backends::S3.port_string
0
+ Technoweenie::AttachmentFu::Backends::S3Backend.port_string
0
           end
0
         end
0
 
0
@@ -251,15 +251,15 @@ module Technoweenie # :nodoc:
0
         end
0
 
0
         def s3_protocol
0
- Technoweenie::AttachmentFu::Backends::S3.protocol
0
+ Technoweenie::AttachmentFu::Backends::S3Backend.protocol
0
         end
0
         
0
         def s3_hostname
0
- Technoweenie::AttachmentFu::Backends::S3.hostname
0
+ Technoweenie::AttachmentFu::Backends::S3Backend.hostname
0
         end
0
           
0
         def s3_port_string
0
- Technoweenie::AttachmentFu::Backends::S3.port_string
0
+ Technoweenie::AttachmentFu::Backends::S3Backend.port_string
0
         end
0
 
0
         protected
...
38
39
40
41
42
43
44
45
 
46
47
48
...
251
252
253
254
 
255
256
257
...
38
39
40
 
 
 
 
 
41
42
43
44
...
247
248
249
 
250
251
252
253
0
@@ -38,11 +38,7 @@ module Mocha
0
     end
0
 
0
     def match?(method_name, *arguments)
0
- if @parameter_block then
0
- @parameter_block.call(*arguments)
0
- else
0
- (@method_name == method_name) and (@parameters == arguments)
0
- end
0
+ (@method_name == method_name) and (@parameter_block ? @parameter_block.call(*arguments) : (@parameters == arguments))
0
     end
0
 
0
     # :startdoc:
0
@@ -251,7 +247,7 @@ module Mocha
0
     end
0
     
0
     def error_message(expected_count, actual_count)
0
- "#{@mock.mocha_inspect}.#{method_signature} - expected calls: #{expected_count}, actual calls: #{actual_count}"
0
+ "#{@mock.mocha_inspect}.#{method_signature} - expected calls: #{expected_count.mocha_inspect}, actual calls: #{actual_count}"
0
     end
0
   
0
     # :startdoc:
...
12
13
14
15
16
17
18
 
 
19
20
 
21
22
23
 
24
25
26
...
12
13
14
 
 
 
 
15
16
17
 
18
19
20
 
21
22
23
24
0
@@ -12,15 +12,13 @@ class Range
0
     1/0.0
0
   end
0
   
0
- alias_method :__to_s__, :to_s
0
-
0
- def to_s
0
- if first.to_f.infinite? then
0
+ def mocha_inspect
0
+ if first.respond_to?(:to_f) and first.to_f.infinite? then
0
       return "at most #{last}"
0
- elsif last.to_f.infinite? then
0
+ elsif last.respond_to?(:to_f) and last.to_f.infinite? then
0
       return "at least #{first}"
0
     else
0
- __to_s__
0
+ to_s
0
     end
0
   end
0
   
...
35
36
37
 
 
 
 
 
38
39
40
...
35
36
37
38
39
40
41
42
43
44
45
0
@@ -35,6 +35,11 @@ class ExpectationTest < Test::Unit::TestCase
0
     assert expectation.match?(:expected_method, 1, 2, 3)
0
   end
0
   
0
+ def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected
0
+ expectation = new_expectation.with() {|x, y, z| x + y == z}
0
+ assert !expectation.match?(:different_method, 1, 2, 3)
0
+ end
0
+
0
   def test_should_not_match_calls_to_different_methods_with_no_parameters
0
     assert !new_expectation.match?(:unexpected_method)
0
   end
...
1
2
 
3
4
5
...
18
19
20
21
 
22
23
24
...
35
36
37
38
 
39
40
41
42
43
 
 
 
 
 
44
45
46
...
1
2
3
4
5
6
...
19
20
21
 
22
23
24
25
...
36
37
38
 
39
40
41
 
 
 
42
43
44
45
46
47
48
49
0
@@ -1,5 +1,6 @@
0
 require File.join(File.dirname(__FILE__), "..", "test_helper")
0
 require 'mocha/infinite_range'
0
+require 'date'
0
 
0
 class InfiniteRangeTest < Test::Unit::TestCase
0
   
0
@@ -18,7 +19,7 @@ class InfiniteRangeTest < Test::Unit::TestCase
0
   end
0
   
0
   def test_should_be_human_readable_description_for_at_least
0
- assert_equal "at least 10", Range.at_least(10).to_s
0
+ assert_equal "at least 10", Range.at_least(10).mocha_inspect
0
   end
0
   
0
   def test_should_include_values_at_or_below_maximum
0
@@ -35,12 +36,14 @@ class InfiniteRangeTest < Test::Unit::TestCase
0
   end
0
   
0
   def test_should_be_human_readable_description_for_at_most
0
- assert_equal "at most 10", Range.at_most(10).to_s
0
+ assert_equal "at most 10", Range.at_most(10).mocha_inspect
0
   end
0
   
0
- def test_should_not_break_original_description
0
- assert_equal "1..10", (1..10).to_s
0
- assert_equal "1...10", (1...10).to_s
0
+ def test_should_be_same_as_standard_to_string
0
+ assert_equal (1..10).to_s, (1..10).mocha_inspect
0
+ assert_equal (1...10).to_s, (1...10).mocha_inspect
0
+ date_range = Range.new(Date.parse('2006-01-01'), Date.parse('2007-01-01'))
0
+ assert_equal date_range.to_s, date_range.mocha_inspect
0
   end
0
   
0
   def assert_false(condition)
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@ module PermalinkFu
0
   
0
   def has_permalink(attr_name, permalink_field = nil)
0
     permalink_field ||= 'permalink'
0
- after_validation { |record| record.send("#{permalink_field}=", PermalinkFu.escape(record.send(attr_name).to_s)) if record.send(permalink_field).to_s.empty? }
0
+ before_validation { |record| record.send("#{permalink_field}=", PermalinkFu.escape(record.send(attr_name).to_s)) if record.send(permalink_field).to_s.empty? }
0
   end
0
 end
0
 
...
2
3
4
 
 
5
6
7
...
2
3
4
5
6
7
8
9
0
@@ -2,6 +2,8 @@ require 'simply_helpful/record_identification_helper'
0
 require 'simply_helpful/record_identifier'
0
 require 'simply_helpful/record_tag_helper'
0
 
0
+require 'simply_helpful/polymorphic_routes'
0
+
0
 require 'simply_helpful/jsg_extensions'
0
 require 'simply_helpful/av_extensions'
0
 require 'simply_helpful/form_helper_extensions'
...
1
2
 
 
 
 
 
 
 
3
4
5
6
7
8
9
 
10
11
12
13
 
 
 
 
 
 
14
15
16
...
22
23
24
25
 
26
27
28
29
 
30
31
32
33
34
35
 
36
...
1
2
3
4
5
6
7
8
9
10
 
 
 
 
 
 
11
12
13
 
 
14
15
16
17
18
19
20
21
22
...
28
29
30
 
31
32
33
34
35
36
37
38
39
40
41
 
42
43
0
@@ -1,16 +1,22 @@
0
 module SimplyHelpful
0
   module ActionControllerExtensions
0
+ POLYMORPHIC_ROUTES = %w(
0
+ polymorphic_url polymorphic_path
0
+ edit_polymorphic_url edit_polymorphic_path
0
+ new_polymorphic_url new_polymorphic_path
0
+ formatted_polymorphic_url formatted_polymorphic_path
0
+ )
0
+
0
     def self.included(base)
0
- base.helper_method :polymorphic_url
0
- base.helper_method :polymorphic_path
0
- end
0
-
0
- def polymorphic_url(record)
0
- SimplyHelpful::RecordIdentifier.polymorphic_url(record, self)
0
+ POLYMORPHIC_ROUTES.each { |route| base.helper_method(route) }
0
     end
0
 
0
- def polymorphic_path(record)
0
- SimplyHelpful::RecordIdentifier.polymorphic_path(record, self)
0
+ POLYMORPHIC_ROUTES.each do |route|
0
+ module_eval <<-EOT
0
+ def #{route}(record)
0
+ SimplyHelpful::PolymorphicRoutes.#{route}(record, self)
0
+ end
0
+ EOT
0
     end
0
     
0
     def redirect_to_with_record_identification(*args)
0
@@ -22,14 +28,15 @@ module SimplyHelpful
0
       when String, Symbol, Hash
0
         redirect_to_without_record_identification *args
0
       else
0
- redirect_to_without_record_identification SimplyHelpful::RecordIdentifier.polymorphic_url(potential_object, self)
0
+ redirect_to_without_record_identification SimplyHelpful::PolymorphicRoutes.polymorphic_url(potential_object, self)
0
       end
0
     end
0
   end
0
 end
0
+
0
 module ActionController
0
   class Base
0
     include SimplyHelpful::ActionControllerExtensions
0
     alias_method_chain :redirect_to, :record_identification
0
   end
0
-end
0
+end
0
\ No newline at end of file
...
18
19
20
21
 
22
23
24
...
18
19
20
 
21
22
23
24
0
@@ -18,7 +18,7 @@ module ActionView
0
           
0
               object_name = SimplyHelpful::RecordIdentifier.singular_class_name(name_or_object)
0
               object = name_or_object
0
- url = SimplyHelpful::RecordIdentifier.polymorphic_url(object, self)
0
+ url = SimplyHelpful::PolymorphicRoutes.polymorphic_url(object, self)
0
           
0
               html_options = if object.new_record?
0
                 { :class => dom_class(object, :new), :id => dom_id(object), :method => :post }
...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
...
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
0
@@ -2,18 +2,6 @@ module SimplyHelpful
0
   module RecordIdentifier
0
     extend self
0
 
0
- def polymorphic_url(record, url_writer)
0
- record.new_record? ?
0
- url_writer.send(plural_class_name(record) + "_url") :
0
- url_writer.send(singular_class_name(record) + "_url", record)
0
- end
0
-
0
- def polymorphic_path(record, url_writer)
0
- record.new_record? ?
0
- url_writer.send(plural_class_name(record) + "_path") :
0
- url_writer.send(singular_class_name(record) + "_path", record)
0
- end
0
-
0
     def partial_path(record_or_class)
0
       klass = class_from_record_or_class(record_or_class)
0
       "#{klass.name.tableize}/#{klass.name.demodulize.underscore}"
...
64
65
66
67
 
68
69
70
...
64
65
66
 
67
68
69
70
0
@@ -64,7 +64,7 @@ module ActionView
0
           when Hash, String, Symbol, NilClass
0
             link_to_without_record_identification(attr_name, record, html_options, *parameters_for_method_reference)
0
           else
0
- url = SimplyHelpful::RecordIdentifier.polymorphic_url(record, self)
0
+ url = SimplyHelpful::PolymorphicRoutes.polymorphic_url(record, self)
0
             link_text = record.respond_to?(attr_name) ? record.send(attr_name) : attr_name
0
             link_to_without_record_identification(link_text, url, html_options, *parameters_for_method_reference)
0
         end
...
77
78
79
80
 
81
...
77
78
79
 
80
81
0
@@ -77,4 +77,4 @@ class NestedRecordIdentifierTest < RecordIdentifierTest
0
     assert_equal expected, partial_path(@record)
0
     assert_equal expected, partial_path(Post::Nested)
0
   end
0
-end
0
+end
0
\ No newline at end of file

Comments

    No one has commented yet.