Changeset 179
- Timestamp:
- 12/12/07 15:49:20 (4 years ago)
- Files:
-
- trunk/lib/globalize/localization/db_translate.rb (modified) (9 diffs)
- trunk/lib/globalize/rails/action_view.rb (modified) (5 diffs)
- trunk/test/db_translation_test.rb (modified) (1 diff)
- trunk/test/mime_responds_test.rb (modified) (3 diffs)
- trunk/test/render_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/globalize/localization/db_translate.rb
r121 r179 673 673 # REDEFINED to include only untranslated fields. We don't want to overwrite the 674 674 # 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) 676 676 if Locale.base? 677 attributes.inject({}) do |quoted, (name, value)|677 quoted = attributes.inject({}) do |quoted, (name, value)| 678 678 if column = column_for_attribute(name) 679 679 quoted[name] = quote_value(value, column) unless !include_primary_key && column.primary … … 682 682 end 683 683 else 684 attributes.inject({}) do |quoted, (name, value)|684 quoted = attributes.inject({}) do |quoted, (name, value)| 685 685 if !self.class.globalize_facets_hash.has_key?(name) && 686 686 column = column_for_attribute(name) … … 690 690 end 691 691 end 692 include_readonly_attributes ? quoted : remove_readonly_attributes(quoted) 692 693 end 693 694 … … 766 767 def find_every(options) 767 768 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?771 769 772 770 # do quick version if base language is active … … 781 779 options[:conditions] = sanitize_sql(options[:conditions]) if options[:conditions] 782 780 783 # there will at least be an +id+ field here784 select_clause = untranslated_fields.map {|f| "#{table_name}.#{f}" }.join(", ")785 786 781 joins_clause = options[:joins].nil? ? "" : options[:joins].dup 787 782 joins_args = [] 788 783 load_full = options[:translate_all] 789 784 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(", ") 790 802 791 803 if Locale.base? … … 878 890 end 879 891 880 options[:select] = s elect_clause892 options[:select] = surrounding_clause % select_clause 881 893 options[:readonly] = false 882 894 … … 905 917 def method_missing(method_id, *arguments) 906 918 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) 908 920 909 921 facets = extract_attribute_names_from_match(match) … … 935 947 936 948 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}" 940 950 end 941 951 elsif match = /find_or_(initialize|create)_by_([_a-zA-Z]\w*)/.match(method_id.to_s) … … 944 954 super unless all_attributes_exists?(facets) 945 955 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 } 948 963 set_readonly_option!(options) 949 964 trunk/lib/globalize/rails/action_view.rb
r35 r179 17 17 # don't use_full_path -- we've already expanded the path 18 18 globalize_old_render_file(localized_path, false, local_assigns) 19 else 19 else 20 20 globalize_old_render_file(template_path, use_full_path, local_assigns) 21 21 end 22 22 end 23 23 24 24 private 25 25 … … 31 31 32 32 def locate_globalize_path(template_path, use_full_path) 33 34 33 active_locale = Globalize::Locale.active 35 34 locale_code = active_locale.code 36 37 cache_key = "#{locale_code}:#{template_path}" 35 cache_key = "#{locale_code}:#{template_path}:#{template_format}" 38 36 cached = @@globalize_path_cache[cache_key] 39 37 return cached if cached … … 46 44 else 47 45 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 48 49 template_file_name = full_template_path(template_path, template_extension) 50 template_extension = template_extension.gsub(/^\w+\./, '') # strip off any formats 49 51 end 50 52 else … … 52 54 template_extension = template_path.split('.').last 53 55 end 54 56 55 57 pn = Pathname.new(template_file_name) 56 58 dir, filename = pn.dirname, pn.basename('.' + template_extension) … … 74 76 localized_path = template_file_name 75 77 end 76 78 77 79 @@globalize_path_cache[cache_key] = localized_path.to_s 78 80 end trunk/test/db_translation_test.rb
r42 r179 373 373 prod.description 374 374 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 376 381 # association building/creating? 377 382 end trunk/test/mime_responds_test.rb
r88 r179 92 92 end 93 93 94 RespondToController.prepend_view_path(File.dirname(__FILE__) + "/views") 94 RespondToController.prepend_view_path(File.dirname(__FILE__) + "/views") 95 95 96 96 class MimeControllerTest < Test::Unit::TestCase … … 243 243 end 244 244 245 def test_with_content_type 245 def test_with_content_type_atom 246 246 @request.env["CONTENT_TYPE"] = "application/atom+xml" 247 247 get :made_for_content_type 248 248 assert_equal "ATOM", @response.body 249 249 end 250 251 def test_with_content_type_rss 250 252 @request.env["CONTENT_TYPE"] = "application/rss+xml" 251 253 get :made_for_content_type … … 253 255 end 254 256 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 258 265 end 259 266 trunk/test/render_test.rb
r88 r179 7 7 end 8 8 9 RenderController.prepend_view_path(File.dirname(__FILE__) + "/views") 9 RenderController.prepend_view_path(File.dirname(__FILE__) + "/views") 10 10 11 11 class RenderControllerTest < Test::Unit::TestCase
