Changeset 179

Show
Ignore:
Timestamp:
12/12/07 15:49:20 (4 years ago)
Author:
yann
Message:

Merge from yann branche

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/globalize/localization/db_translate.rb

    r121 r179  
    673673        # REDEFINED to include only untranslated fields. We don't want to overwrite the 
    674674        # base translation with other translations. 
    675         def attributes_with_quotes(include_primary_key = true
     675        def attributes_with_quotes(include_primary_key = true, include_readonly_attributes = true
    676676          if Locale.base? 
    677             attributes.inject({}) do |quoted, (name, value)| 
     677            quoted = attributes.inject({}) do |quoted, (name, value)| 
    678678              if column = column_for_attribute(name) 
    679679                quoted[name] = quote_value(value, column) unless !include_primary_key && column.primary 
     
    682682            end 
    683683          else 
    684             attributes.inject({}) do |quoted, (name, value)| 
     684            quoted = attributes.inject({}) do |quoted, (name, value)| 
    685685              if !self.class.globalize_facets_hash.has_key?(name) && 
    686686                  column = column_for_attribute(name) 
     
    690690            end 
    691691          end 
     692                include_readonly_attributes ? quoted : remove_readonly_attributes(quoted) 
    692693        end 
    693694 
     
    766767        def find_every(options) 
    767768          return globalize_old_find_every(options) if options[:untranslated] 
    768           raise StandardError, 
    769             ":select option not allowed on translatable models " + 
    770             "(#{options[:select]})" if options[:select] && !options[:select].empty? 
    771769 
    772770          # do quick version if base language is active 
     
    781779          options[:conditions] = sanitize_sql(options[:conditions]) if options[:conditions] 
    782780 
    783           # there will at least be an +id+ field here 
    784           select_clause = untranslated_fields.map {|f| "#{table_name}.#{f}" }.join(", ") 
    785  
    786781          joins_clause = options[:joins].nil? ? "" : options[:joins].dup 
    787782          joins_args = [] 
    788783          load_full = options[:translate_all] 
    789784          facets = load_full ? globalize_facets : preload_facets 
     785 
     786          if options[:select].nil? || options[:select] = '*' 
     787            surrounding_clause = '%s' 
     788          else 
     789            surrounding_clause = options[:select] 
     790            re_select = Regexp.new("#{table_name}.*") 
     791            if surrounding_clause =~ re_select 
     792              surrounding_clause = surrounding_clause.gsub(re_select, '%s') 
     793            else 
     794              raise StandardError, 
     795              "this :select option format is not allowed on translatable models " + 
     796              "(#{options[:select]})" 
     797            end 
     798          end 
     799 
     800          # there will at least be an +id+ field here 
     801          select_clause = untranslated_fields.map {|f| "#{table_name}.#{f}" }.join(", ") 
    790802 
    791803          if Locale.base? 
     
    878890          end 
    879891 
    880           options[:select] = select_clause 
     892          options[:select] = surrounding_clause % select_clause 
    881893          options[:readonly] = false 
    882894 
     
    905917      def method_missing(method_id, *arguments) 
    906918        if match = /find_(all_by|by)_([_a-zA-Z]\w*)/.match(method_id.to_s) 
    907           finder, deprecated_finder = determine_finder(match), determine_deprecated_finder(match) 
     919          finder = determine_finder(match) 
    908920 
    909921          facets = extract_attribute_names_from_match(match) 
     
    935947 
    936948            else 
    937               ActiveSupport::Deprecation.silence do 
    938                 send(deprecated_finder, sanitize_sql(attributes), *arguments[facets.length..-1]) 
    939               end 
     949              raise ArgumentError, "Unrecognized arguments for #{method_id}: #{extra_options.inspect}" 
    940950          end 
    941951        elsif match = /find_or_(initialize|create)_by_([_a-zA-Z]\w*)/.match(method_id.to_s) 
     
    944954          super unless all_attributes_exists?(facets) 
    945955 
    946           attributes = construct_attributes_from_arguments(facets, arguments) 
    947           options = { :conditions => attributes } 
     956          if arguments[0].is_a?(Hash) 
     957            attributes = arguments[0].with_indifferent_access 
     958            find_attributes = attributes.slice(*facets) 
     959          else 
     960            find_attributes = attributes = construct_attributes_from_arguments(facets, arguments) 
     961          end 
     962          options = { :conditions => find_attributes } 
    948963          set_readonly_option!(options) 
    949964 
  • trunk/lib/globalize/rails/action_view.rb

    r35 r179  
    1717        # don't use_full_path -- we've already expanded the path 
    1818        globalize_old_render_file(localized_path, false, local_assigns) 
    19       else  
     19      else 
    2020        globalize_old_render_file(template_path, use_full_path, local_assigns) 
    2121      end 
    2222    end 
    23      
     23   
    2424    private 
    2525     
     
    3131       
    3232      def locate_globalize_path(template_path, use_full_path) 
    33        
    3433        active_locale = Globalize::Locale.active 
    3534        locale_code = active_locale.code 
    36  
    37         cache_key = "#{locale_code}:#{template_path}" 
     35        cache_key = "#{locale_code}:#{template_path}:#{template_format}" 
    3836        cached = @@globalize_path_cache[cache_key] 
    3937        return cached if cached 
     
    4644          else 
    4745            template_extension = pick_template_extension(template_path).to_s 
     46            unless template_extension 
     47              raise ActionViewError, "No #{template_handler_preferences.to_sentence} template found for #{template_path} in #{view_paths.inspect}" 
     48            end 
    4849            template_file_name = full_template_path(template_path, template_extension) 
     50            template_extension = template_extension.gsub(/^\w+\./, '') # strip off any formats 
    4951          end 
    5052        else 
     
    5254          template_extension = template_path.split('.').last 
    5355        end 
    54  
     56         
    5557        pn = Pathname.new(template_file_name) 
    5658        dir, filename = pn.dirname, pn.basename('.' + template_extension) 
     
    7476          localized_path = template_file_name 
    7577        end 
    76  
     78         
    7779        @@globalize_path_cache[cache_key] = localized_path.to_s 
    7880      end 
  • trunk/test/db_translation_test.rb

    r42 r179  
    373373      prod.description 
    374374  end 
    375  
     375   
     376  def test_product_show_is_language_code 
     377    prod = Product.find(1) 
     378    assert_equal('en', prod.language_code) 
     379  end 
     380   
    376381  # association building/creating? 
    377382end 
  • trunk/test/mime_responds_test.rb

    r88 r179  
    9292end 
    9393 
    94 RespondToController.prepend_view_path(File.dirname(__FILE__) + "/views") 
     94RespondToController.prepend_view_path(File.dirname(__FILE__) + "/views")  
    9595 
    9696class MimeControllerTest < Test::Unit::TestCase 
     
    243243  end 
    244244 
    245   def test_with_content_type 
     245  def test_with_content_type_atom 
    246246    @request.env["CONTENT_TYPE"] = "application/atom+xml" 
    247247    get :made_for_content_type 
    248248    assert_equal "ATOM", @response.body 
    249  
     249  end 
     250   
     251  def test_with_content_type_rss 
    250252    @request.env["CONTENT_TYPE"] = "application/rss+xml" 
    251253    get :made_for_content_type 
     
    253255  end 
    254256 
    255   def test_fr_with_content_type 
    256     Locale.set('fr') 
    257     test_with_content_type 
     257  def test_fr_with_content_type_atom 
     258    Locale.set('fr') 
     259    test_with_content_type_atom 
     260  end 
     261 
     262  def test_fr_with_content_type_rss 
     263    Locale.set('fr') 
     264    test_with_content_type_rss 
    258265  end 
    259266 
  • trunk/test/render_test.rb

    r88 r179  
    77end 
    88 
    9 RenderController.prepend_view_path(File.dirname(__FILE__) + "/views") 
     9RenderController.prepend_view_path(File.dirname(__FILE__) + "/views")  
    1010 
    1111class RenderControllerTest < Test::Unit::TestCase