<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>engines/adva_cms/db/migrate/20090702085459_create_section_translations.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -2,6 +2,7 @@ class Section &lt; ActiveRecord::Base
   @@types = ['Page']
   cattr_reader :types
 
+  translates :title
   serialize :permissions
 
   has_option :contents_per_page, :default =&gt; 15</diff>
      <filename>engines/adva_cms/app/models/section.rb</filename>
    </modified>
    <modified>
      <diff>@@ -22,6 +22,19 @@ namespace :adva do
         puts comp_keys - base_keys
       end
     end
+    
+    desc &quot;Migrate section titles. Specify e.g., LOCALE=de if app locale isn't en.&quot;
+    task :migrate_sections =&gt; :environment do
+      locale = ENV['locale'] || 'en'
+      sql = %{
+        INSERT INTO section_translations (section_id, locale, title, created_at, updated_at)
+        SELECT sections.id, &quot;#{locale}&quot;, sections.title, sections.published_at, sections.published_at
+        FROM sections
+      }
+      ActiveRecord::Base.connection.insert sql, &quot;migrating sections to globalize&quot;
+      ActiveRecord::Base.connection.remove_column 'sections', 'title'
+      Rake::Task['db:schema:dump'].invoke
+    end
   end
 end
 </diff>
      <filename>engines/adva_cms/lib/tasks/translation.rake</filename>
    </modified>
    <modified>
      <diff>@@ -120,6 +120,11 @@ class BaseHelperMicroformatsTest &lt; ActiveSupport::TestCase
     @local_time = Time.zone.local 2008, 10, 9, 14, 0, 0
   end
 
+  def teardown
+    super
+    Time.zone   = 'UTC'
+  end
+  
   # DATETIME MICROFORMAT HELPERS
 
   test &quot;#datetime_with_microformat displays the passed object when passed a non-Date/Time object&quot; do</diff>
      <filename>engines/adva_cms/test/unit/helpers/base_helper_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -109,7 +109,7 @@ module Globalize
         end
 
         module InstanceMethods
-          def reload_with_globalize
+          def reload_with_globalize(options = nil)
             globalize.clear
 
             # clear all globalized attributes
@@ -118,9 +118,13 @@ module Globalize
               @attributes.delete attr.to_s
             end
 
-            reload_without_globalize
+            reload_without_globalize(options)
           end
 
+          def translated_attributes
+            self.class.globalize_options[:translated_attributes].inject({}) {|h, tf| h[tf] = send(tf); h }
+          end
+          
           def globalize
             @globalize ||= Adapter.new self
           end</diff>
      <filename>engines/adva_cms/vendor/plugins/globalize2/lib/globalize/model/active_record/translated.rb</filename>
    </modified>
    <modified>
      <diff>@@ -20,10 +20,10 @@ module With
     
     def it_updates(*names)
       names.each do |name|
-        before { record_before_state(&quot;@#{name}.attributes&quot;) }
+        before { record_before_state(&quot;all_attributes(@#{name})&quot;) }
         assertion &quot;it updates #{name}&quot; do
-          previous = @before_states[&quot;@#{name}.attributes&quot;]
-          current = assigns(name).reload.attributes
+          previous = @before_states[&quot;all_attributes(@#{name})&quot;]
+          current = all_attributes(assigns(name).reload)
           assert_not_equal previous, current, &quot;expected #{name} to be updated, but wasn't&quot;
         end
       end
@@ -125,6 +125,13 @@ module With
       @before_states[expression] = instance_eval(expression)
     end
   
+    # merges in translated attributes, if present
+    def all_attributes(model)
+      model.respond_to?(:translated_attributes) ?
+        model.attributes.merge( model.translated_attributes ) :
+        model.attributes
+    end
+    
     def assert_state_change(expression, difference, message = nil)
       expected = @before_states[expression] + difference
       result   = instance_eval(expression)</diff>
      <filename>test/with-sugar/lib/with-sugar/model.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>14fef3be89bdc1d75e470bbb523d346c1037f7fc</id>
    </parent>
  </parents>
  <author>
    <name>Joshua Harvey</name>
    <email>joshmh@gmail.com</email>
  </author>
  <url>http://github.com/svenfuchs/adva_cms/commit/2e97c397f3fa9a1c91b075e9eae461949f8c9162</url>
  <id>2e97c397f3fa9a1c91b075e9eae461949f8c9162</id>
  <committed-date>2009-07-02T05:45:37-07:00</committed-date>
  <authored-date>2009-07-02T05:45:37-07:00</authored-date>
  <message>translated section titles; all tests pass</message>
  <tree>917600d5f800918332bc1f8859a1a62326ca7c3d</tree>
  <committer>
    <name>Joshua Harvey</name>
    <email>joshmh@gmail.com</email>
  </committer>
</commit>
