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 mocha, liquid, acts_as_versioned, and simply_helpful plugins

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2593 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Tue Dec 26 14:16:43 -0800 2006
commit  bfb170dec51c76d3b1a6f368a8965e7524991f66
tree    5bfd61fbfff2f7ddae6f1c250a6ac89ad589d61a
parent  ad98d631ec33887a5b4f9745799a9f9fa7725769
...
392
393
394
395
 
396
397
398
 
 
 
 
399
400
401
...
392
393
394
 
395
396
 
 
397
398
399
400
401
402
403
0
@@ -392,10 +392,12 @@ module ActiveRecord #:nodoc:
0
           def clear_changed_attributes
0
             self.changed_attributes = []
0
           end
0
-
0
+
0
           def write_changed_attribute(attr_name, attr_value)
0
- (self.changed_attributes ||= []) << attr_name.to_s unless self.changed?(attr_name) or self.send(attr_name) == attr_value
0
- write_attribute(attr_name.to_s, attr_value)
0
+ # Convert to db type for comparison. Avoids failing Float<=>String comparisons.
0
+ attr_value_for_db = self.class.columns_hash[attr_name.to_s].type_cast(attr_value)
0
+ (self.changed_attributes ||= []) << attr_name.to_s unless self.changed?(attr_name) || self.send(attr_name) == attr_value_for_db
0
+ write_attribute(attr_name, attr_value_for_db)
0
           end
0
 
0
         private
...
50
51
52
53
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
50
51
52
 
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
0
@@ -50,4 +50,19 @@ ActiveRecord::Schema.define(:version => 0) do
0
     t.column :version, :integer
0
     t.column :updated_at, :datetime
0
   end
0
-end
0
\ No newline at end of file
0
+
0
+ create_table :landmarks, :force => true do |t|
0
+ t.column :name, :string
0
+ t.column :latitude, :float
0
+ t.column :longitude, :float
0
+ t.column :version, :integer
0
+ end
0
+
0
+ create_table :landmark_versions, :force => true do |t|
0
+ t.column :landmark_id, :integer
0
+ t.column :name, :string
0
+ t.column :latitude, :float
0
+ t.column :longitude, :float
0
+ t.column :version, :integer
0
+ end
0
+end
...
3
4
5
6
 
7
8
9
...
300
301
302
 
 
 
 
 
 
 
 
 
 
303
...
3
4
5
 
6
7
8
9
...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
0
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'fixtures/page')
0
 require File.join(File.dirname(__FILE__), 'fixtures/widget')
0
 
0
 class VersionedTest < Test::Unit::TestCase
0
- fixtures :pages, :page_versions, :locked_pages, :locked_pages_revisions, :authors
0
+ fixtures :pages, :page_versions, :locked_pages, :locked_pages_revisions, :authors, :landmarks, :landmark_versions
0
 
0
   def test_saves_versioned_copy
0
     p = Page.create :title => 'first title', :body => 'first body'
0
@@ -300,4 +300,14 @@ class VersionedTest < Test::Unit::TestCase
0
     page_version = page.versions.last
0
     assert_equal page, page_version.page
0
   end
0
+
0
+ def test_unchanged_attributes
0
+ landmarks(:washington).attributes = landmarks(:washington).attributes
0
+ assert !landmarks(:washington).changed?
0
+ end
0
+
0
+ def test_unchanged_string_attributes
0
+ landmarks(:washington).attributes = landmarks(:washington).attributes.inject({}) { |params, (key, value)| params.update key => value.to_s }
0
+ assert !landmarks(:washington).changed?
0
+ end
0
 end
...
8
9
10
 
11
12
13
14
15
16
17
 
 
 
 
 
 
18
19
20
21
22
23
...
8
9
10
11
12
13
14
 
 
 
 
15
16
17
18
19
20
21
 
 
22
23
24
0
@@ -8,16 +8,17 @@ module Liquid
0
     def initialize(markup)
0
       @markup = markup
0
       @name = markup.match(/\s*(#{QuotedFragment})/)[1]
0
+ @filters = []
0
       if markup.match(/#{FilterSperator}\s*(.*)/)
0
         filters = Regexp.last_match(1).split(/#{FilterSperator}/)
0
         
0
- @filters = filters.collect do |f|
0
- filtername = f.match(/\s*(\w+)/)[1]
0
- filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*(#{QuotedFragment})/).flatten
0
- [filtername.to_sym, filterargs]
0
+ filters.each do |f|
0
+ if matches = f.match(/\s*(\w+)/)
0
+ filtername = matches[1]
0
+ filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*(#{QuotedFragment})/).flatten
0
+ @filters << [filtername.to_sym, filterargs]
0
+ end
0
         end
0
- else
0
- @filters = []
0
       end
0
     end
0
 
...
11
12
13
 
 
 
 
 
 
 
 
14
15
...
11
12
13
14
15
16
17
18
19
20
21
22
23
0
@@ -11,4 +11,12 @@ class ParsingQuirksTest < Test::Unit::TestCase
0
     assert_equal text, template.render
0
     assert_equal [String], template.root.nodelist.collect {|i| i.class}
0
   end
0
+
0
+ def test_error_on_empty_filter
0
+ assert_nothing_raised do
0
+ Template.parse("{{test |a|b|}}")
0
+ Template.parse("{{test}}")
0
+ Template.parse("{{|test|}}")
0
+ end
0
+ end
0
 end
0
\ No newline at end of file
...
23
24
25
26
 
27
28
29
...
88
89
90
91
 
92
93
94
...
23
24
25
 
26
27
28
29
...
88
89
90
 
91
92
93
94
0
@@ -23,7 +23,7 @@ Rake::RDocTask.new do |task|
0
   task.rdoc_dir = 'doc'
0
   task.template = "html_with_google_analytics"
0
   task.options << "--line-numbers" << "--inline-source"
0
- task.rdoc_files.include('README', 'RELEASE', 'COPYING', 'MIT-LICENSE', 'agiledox.txt', 'lib/mocha/auto_verify.rb', 'lib/mocha/mock_methods.rb', 'lib/mocha/expectation.rb', 'lib/stubba/object.rb')
0
+ task.rdoc_files.include('README', 'RELEASE', 'COPYING', 'MIT-LICENSE', 'agiledox.txt', 'lib/mocha/auto_verify.rb', 'lib/mocha/mock_methods.rb', 'lib/mocha/expectation.rb', 'lib/mocha/object.rb')
0
 end
0
 task :rdoc => :examples
0
 
0
@@ -88,7 +88,7 @@ specification = Gem::Specification.new do |s|
0
   s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers'
0
                          
0
   s.autorequire = 'mocha'
0
- s.files = FileList['{lib,test}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
0
+ s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
0
   s.test_file = "test/all_tests.rb"
0
 end
0
 
...
2
3
4
5
 
6
7
8
...
2
3
4
 
5
6
7
8
0
@@ -2,7 +2,7 @@ require 'date'
0
 
0
 class Object
0
   def mocha_inspect
0
- inspect =~ /#</ ? "#<#{self.class}: #{self.object_id}>" : inspect
0
+ inspect =~ /#</ ? "#<#{self.class}:0x#{self.object_id.to_s(16)}>" : inspect
0
   end
0
 end
0
 
...
17
18
19
20
 
21
22
23
...
17
18
19
 
20
21
22
23
0
@@ -17,7 +17,7 @@ class ObjectInspectTest < Test::Unit::TestCase
0
   
0
   def test_should_provide_custom_representation_of_object
0
     object = Object.new
0
- assert_equal "#<#{object.class}: #{object.object_id}>", object.mocha_inspect
0
+ assert_equal "#<#{object.class}:#{"0x%x" % object.object_id}>", object.mocha_inspect
0
   end
0
   
0
 end
...
1
2
3
 
 
 
...
1
 
2
3
4
5
0
@@ -1,2 +1,4 @@
0
 require 'simply_helpful'
0
-ActionController::Base.helper(SimplyHelpful::RecordIdentificationHelper, SimplyHelpful::RecordTagHelper)
0
\ No newline at end of file
0
+ActionController::Base.send :include, SimplyHelpful::RecordIdentificationHelper
0
+ActionController::Base.helper SimplyHelpful::RecordIdentificationHelper,
0
+ SimplyHelpful::RecordTagHelper
...
4
5
6
7
8
 
 
9
...
4
5
6
 
7
8
9
10
0
@@ -4,4 +4,5 @@ require 'simply_helpful/record_tag_helper'
0
 
0
 require 'simply_helpful/jsg_extensions'
0
 require 'simply_helpful/av_extensions'
0
-require 'simply_helpful/form_helper_extensions'
0
\ No newline at end of file
0
+require 'simply_helpful/form_helper_extensions'
0
+require 'simply_helpful/controller_extensions'
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.named_route(object, self)
0
+ url = SimplyHelpful::RecordIdentifier.polymorphic_url(object, self)
0
           
0
               html_options = if object.new_record?
0
                 { :class => dom_class(object, :new), :id => dom_id(object), :method => :post }
...
1
2
3
4
5
6
7
8
9
 
 
 
 
10
11
12
13
 
 
 
 
 
 
 
14
15
16
 
...
1
2
 
 
 
 
 
 
 
3
4
5
6
7
 
 
 
8
9
10
11
12
13
14
15
 
16
17
0
@@ -1,15 +1,16 @@
0
 module SimplyHelpful
0
   module RecordIdentificationHelper
0
- def partial_path(*args, &block)
0
- RecordIdentifier.partial_path(*args, &block)
0
- end
0
-
0
- def dom_class(*args, &block)
0
- RecordIdentifier.dom_class(*args, &block)
0
- end
0
+ protected
0
+ def partial_path(*args, &block)
0
+ RecordIdentifier.partial_path(*args, &block)
0
+ end
0
 
0
- def dom_id(*args, &block)
0
- RecordIdentifier.dom_id(*args, &block)
0
- end
0
+ def dom_class(*args, &block)
0
+ RecordIdentifier.dom_class(*args, &block)
0
+ end
0
+
0
+ def dom_id(*args, &block)
0
+ RecordIdentifier.dom_id(*args, &block)
0
+ end
0
   end
0
-end
0
\ No newline at end of file
0
+end
...
2
3
4
5
 
6
7
8
9
10
 
 
 
 
 
 
11
12
13
...
2
3
4
 
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
0
@@ -2,12 +2,18 @@ module SimplyHelpful
0
   module RecordIdentifier
0
     extend self
0
 
0
- def named_route(record, url_writer)
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}"
...
1
2
 
 
 
 
 
 
 
 
 
 
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
 
7
8
9
...
18
19
20
21
22
 
 
 
23
24
25
...
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
...
64
65
66
 
 
67
68
69
70
71
72
0
@@ -1,9 +1,55 @@
0
 module SimplyHelpful
0
   module RecordTagHelper
0
+ # Produces a wrapper DIV element with id and class parameters that
0
+ # relate to the specified ActiveRecord object. Usage example:
0
+ #
0
+ # <% div_for(@person, :class => "foo") do %>
0
+ # <%=h @person.name %>
0
+ # <% end %>
0
+ #
0
+ # produces:
0
+ #
0
+ # <div id="person_123" class="person foo"> Joe Bloggs </div>
0
+ #
0
     def div_for(record, *args, &block)
0
+ content_tag_for(:div, record, *args, &block)
0
+ end
0
+
0
+ # content_tag_for creates an HTML element with id and class parameters
0
+ # that relate to the specified ActiveRecord object. For example:
0
+ #
0
+ # <% content_tag_for(:tr, @person) do %>
0
+ # <td><%=h @person.first_name %></td>
0
+ # <td><%=h @person.last_name %></td>
0
+ # <% end %>
0
+ #
0
+ # would produce hthe following HTML (assuming @person is an instance of
0
+ # a Person object, with an id value of 123):
0
+ #
0
+ # <tr id="person_123" class="person">....</tr>
0
+ #
0
+ # If you require the HTML id attribute to have a prefix, you can specify it:
0
+ #
0
+ # <% content_tag_for(:tr, @person, :foo) do %> ...
0
+ #
0
+ # produces:
0
+ #
0
+ # <tr id="foo_person_123" class="person">...
0
+ #
0
+ # content_tag_for also accepts a hash of options, which will be converted to
0
+ # additional HTML attributes. If you specify a +:class+ value, it will be combined
0
+ # with the default class name for your object. For example:
0
+ #
0
+ # <% content_tag_for(:li, @person, :class => "bar") %>...
0
+ #
0
+ # produces:
0
+ #
0
+ # <li id="person_123" class="person bar">...
0
+ #
0
+ def content_tag_for(tag_name, record, *args, &block)
0
       prefix = args.first.is_a?(Hash) ? nil : args.shift
0
       options = args.first.is_a?(Hash) ? args.shift : {}
0
- concat content_tag(:div, capture(&block),
0
+ concat content_tag(tag_name, capture(&block),
0
         options.merge({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) })),
0
         block.binding
0
     end
0
@@ -18,8 +64,9 @@ 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.named_route(record, self)
0
- link_to_without_record_identification(record.send(attr_name), url, html_options, *parameters_for_method_reference)
0
+ url = SimplyHelpful::RecordIdentifier.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
0
       end
0
       
...
65
66
67
68
 
69
70
71
...
90
91
92
93
 
94
95
96
97
...
65
66
67
 
68
69
70
71
...
90
91
92
 
93
94
95
96
97
0
@@ -65,7 +65,7 @@ class FormHelperExtensionsTest < Test::Unit::TestCase
0
     _erbout = ''
0
     form_for(@record) {}
0
     
0
- expected = "<form action='#{post_url(@record)}' class='edit_post' id='edit_post_1' method='post'><input type='hidden' name='_method' value='put' /></form>"
0
+ expected = "<form action='#{post_url(@record)}' class='edit_post' id='edit_post_1' method='post'><div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div></form>"
0
     assert_dom_equal expected, _erbout
0
   end
0
 
0
@@ -90,7 +90,7 @@ class FormHelperExtensionsTest < Test::Unit::TestCase
0
     _erbout = ''
0
     remote_form_for(@record) {}
0
     
0
- expected = %(<form action='#{post_url(@record)}' onsubmit="new Ajax.Request('#{post_url(@record)}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='edit_post' id='edit_post_1' method='post'><input type='hidden' name='_method' value='put' /></form>)
0
+ expected = %(<form action='#{post_url(@record)}' id='edit_post_1' method='post' onsubmit="new Ajax.Request('#{post_url(@record)}', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" class='edit_post'><div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div></form>)
0
     assert_dom_equal expected, _erbout
0
   end
0
 end
0
\ No newline at end of file
...
12
13
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
16
17
...
74
75
76
 
 
 
 
 
 
 
 
77
78
...
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
...
122
123
124
125
126
127
128
129
130
131
132
133
134
0
@@ -12,6 +12,54 @@ class RecordTagHelperTest < Test::Unit::TestCase
0
     @record = Post.new
0
   end
0
   
0
+ def test_content_tag_for_with_new_record
0
+ _erbout = ''
0
+ content_tag_for(:li, @record) {}
0
+
0
+ expected = "<li class='post' id='new_post'></li>"
0
+ assert_dom_equal expected, _erbout
0
+ end
0
+
0
+ def test_content_tag_for_with_existing_record
0
+ @record.save
0
+ _erbout = ''
0
+ content_tag_for(:li, @record) {}
0
+
0
+ expected = "<li class='post' id='post_1'></li>"
0
+ assert_dom_equal expected, _erbout
0
+ end
0
+
0
+ def test_content_tag_for_merges_given_class_names
0
+ _erbout = ''
0
+ content_tag_for(:li, @record, :class => 'foo') {}
0
+
0
+ expected = "<li class='post foo' id='new_post'></li>"
0
+ assert_dom_equal expected, _erbout
0
+
0
+ _erbout = ''
0
+ content_tag_for(:li, @record, :class => 'foo bar') {}
0
+
0
+ expected = "<li class='post foo bar' id='new_post'></li>"
0
+ assert_dom_equal expected, _erbout
0
+ end
0
+
0
+ def test_content_tag_for_with_dom_id_prefix_on_new_record
0
+ _erbout = ''
0
+ content_tag_for(:li, @record, :foo, :class => 'foo') {}
0
+
0
+ expected = "<li class='post foo' id='foo_post'></li>"
0
+ assert_dom_equal expected, _erbout
0
+ end
0
+
0
+ def test_content_tag_for_with_dom_id_prefix_on_existing_record
0
+ @record.save
0
+ _erbout = ''
0
+ content_tag_for(:li, @record, :foo, :class => 'foo') {}
0
+
0
+ expected = "<li class='post foo' id='foo_post_1'></li>"
0
+ assert_dom_equal expected, _erbout
0
+ end
0
+
0
   def test_div_for_with_new_record
0
     _erbout = ''
0
     div_for(@record) {}
0
@@ -74,4 +122,12 @@ class RecordTagHelperTest < Test::Unit::TestCase
0
     expected = "<a href='http://www.example.com/posts/1'>post #1</a>"
0
     assert_dom_equal expected, actual
0
   end
0
+
0
+ def test_link_to_with_an_existing_method_and_constant_text
0
+ @record.save
0
+ actual = link_to "Cancel Editing", @record
0
+
0
+ expected = "<a href='http://www.example.com/posts/1'>Cancel Editing</a>"
0
+ assert_dom_equal expected, actual
0
+ end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.