Changeset 1342
- Timestamp:
- 02/13/08 16:37:22 (1 year ago)
- Files:
-
- org.jalcedo.babel.database/trunk/models/babel/dictionary.rb (modified) (1 diff)
- org.jalcedo.babel.database/trunk/models/babel/register.rb (modified) (1 diff)
- org.jalcedo.babel.database/trunk/models/babel/translation.rb (modified) (1 diff)
- org.jalcedo.babel.database/trunk/spec/babel/register_spec.rb (modified) (4 diffs)
- org.jalcedo.babel.database/trunk/spec/helper/translation_helper.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
org.jalcedo.babel.database/trunk/models/babel/dictionary.rb
r1337 r1342 1 require 'active_support' 1 2 2 3 module Babel 3 4 # Dictionary of any languages. 4 5 class Dictionary 6 @@default_dictionaries = {} 7 cattr_accessor :default_dictionaries 8 5 9 class << self 6 10 # find a dictionary for iso_code. 7 11 def find iso_code 8 return JapaneaseDictionary.new if iso_code == 'ja'9 nil12 Dictionary.default_dictionaries['ja'] ||= JapaneaseDictionary.new 13 return Dictionary.default_dictionaries[iso_code] 10 14 end 11 15 end org.jalcedo.babel.database/trunk/models/babel/register.rb
r1341 r1342 4 4 class Register 5 5 def initialize project, version, username, language_iso 6 6 unless project && version && username && language_iso 7 raise ArgumentError, 'project or version or username or language code is nil.' 8 end 9 if File.count(:conditions => ['project_id = ? and version = ?', project, version]) == 0 then 10 raise ArgumentError, 'project_version is not exist.' 11 end 12 @project_id = project 13 @version = version 14 unless @user = User.find_by_username(username) 15 raise ArgumentError, 'user is not exist.' 16 end 17 unless @language = Language.find_by_iso_code(language_iso) 18 raise ArgumentError, 'language is not exist.' 19 end 20 unless @dictionary = Dictionary.find(language_iso) 21 raise ArgumentError, "Dictionary is not exist associate with #{language_iso}." 22 end 7 23 end 8 24 9 25 def register 10 26 String.transaction do 27 self.files.each do |file| 28 String.find_all_by_file_id(file.id).each do |string| 29 tr = Translation.new 30 tr.string_id = string.id 31 tr.language = @language 32 tr.value = @dictionary.lookup(string.value) 33 tr.user = @user 34 tr.save! 35 end 36 end 37 end 11 38 end 39 40 def files 41 File.find(:all, :select => 'file_id', 42 :conditions => ['project_id = ? and version = ?', @project_id, @version] 43 ) 44 end 45 12 46 end 13 47 end org.jalcedo.babel.database/trunk/models/babel/translation.rb
r1341 r1342 8 8 belongs_to :user, :foreign_key => "userid" 9 9 10 def validate_on_create 11 return unless active_translation = Translation.find(:first, 12 :conditions => ['string_id and language_id and is_active', string_id, language_id, 1] 13 ) 14 if active_translation.value == value 15 errors.add(:value, 'Same value on active translation.') 16 end 17 end 18 10 19 def before_create 11 20 Translation.update_all('is_active = 0', "string_id = #{string_id} and language_id = #{language_id}") org.jalcedo.babel.database/trunk/spec/babel/register_spec.rb
r1341 r1342 56 56 before(:all) do 57 57 @japanease = Babel::Language.find_by_iso_code('ja') 58 @register = Babel::Register.new('eclipse', '3.3', 'babel@eclipse.org', 'ja') 58 59 end 59 60 … … 62 63 end 63 64 65 it 'should have files of Eclipse 3.3.' do 66 @register.should have_at_least(1).files 67 end 68 69 it 'files should have only file_id attribute.' do 70 @register.files.each do | file | 71 file.id.should_not be_nil 72 file[:name].should be_nil 73 file[:project_id].should be_nil 74 file[:version].should be_nil 75 file[:is_active].should be_nil 76 end 77 end 78 64 79 it 'should increse Japanease translations on Eclipse 3.3 strings.' do 65 80 lambda { 66 Babel::Register.new('eclipse', '3.3', 'babel@eclipse.org', 'ja').register81 @register.register 67 82 }.should change{ 68 83 Babel::Translation.count( … … 75 90 it 'should not increase other translations.' do 76 91 lambda { 77 Babel::Register.new('eclipse', '3.3', 'babel@eclipse.org', 'ja').register92 @register.register 78 93 }.should_not change{ 79 94 Babel::Translation.count( … … 86 101 it "should not increase other project version's translations. " do 87 102 lambda { 88 Babel::Register.new('eclipse', '3.3', 'babel@eclipse.org', 'ja').register103 @register.register 89 104 }.should_not change{ 90 105 Babel::Translation.count( org.jalcedo.babel.database/trunk/spec/helper/translation_helper.rb
r1341 r1342 1 require 'babel/language' 2 require 'babel/user' 3 require 'babel/translation' 1 4 2 5 module TranslationHelper
