Changeset 1344

Show
Ignore:
Timestamp:
02/13/08 18:19:38 (1 year ago)
Author:
yuanying
Message:

maybe mission complete.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • org.jalcedo.babel.database/trunk/Rakefile

    r1337 r1344  
    99desc "Run all specs" 
    1010Spec::Rake::SpecTask.new('specs') do |t| 
    11   ENV["APP_ENV"] = 'test' 
    12    
    1311  t.spec_opts = ["--format", "specdoc", "--colour"] 
    1412  t.spec_files = Dir['spec/**/*_spec.rb'].sort 
    1513end 
     14 
     15desc 'Register translated words.' 
     16task :register do 
     17  require 'init' 
     18  project = ENV['project'] ? ENV['project'] : 'eclipse' 
     19  version = ENV['version'] ? ENV['version'] : '3.3' 
     20  user = ENV['user'] 
     21  lang = ENV['language'] ? ENV['language'] : 'ja' 
     22   
     23  Babel::Register.new(project, version, user, lang).register 
     24end 
  • org.jalcedo.babel.database/trunk/init.rb

    r1341 r1344  
    1 ENV["APP_ENV"] ||= 'development' 
     1ENV["APP_ENV"] ||= 'test' 
    22 
    3 require 'java' 
    43require 'yaml' 
    5 require 'rubygems' 
    6  
    7 require 'active_record' 
    84 
    95APP_ROOT = "#{File.dirname(__FILE__)}" unless defined?(APP_ROOT) 
     
    1511$:.unshift File.join(APP_ROOT, 'spec', 'helper') if ENV["APP_ENV"] == 'test' 
    1612 
     13require 'babel' 
     14 
    1715ActiveRecord::Base.establish_connection(DATABASE_CONFIG[ENV["APP_ENV"]]) 
  • org.jalcedo.babel.database/trunk/models/babel/dictionary.rb

    r1342 r1344  
    1010      # find a dictionary for iso_code. 
    1111      def find iso_code 
    12         Dictionary.default_dictionaries['ja'] ||= JapaneaseDictionary.new 
    1312        return Dictionary.default_dictionaries[iso_code] 
    1413      end 
  • org.jalcedo.babel.database/trunk/models/babel/register.rb

    r1342 r1344  
    2626      String.transaction do 
    2727        self.files.each do |file| 
     28          #puts "files is #{file.id}" 
    2829          String.find_all_by_file_id(file.id).each do |string| 
     30            #puts "string is #{string.id}" 
    2931            tr = Translation.new 
    3032            tr.string_id = string.id 
     
    3234            tr.value = @dictionary.lookup(string.value) 
    3335            tr.user = @user 
    34             tr.save! 
     36            # TODO validate tr and logged. 
     37            tr.save 
    3538          end 
    3639        end 
  • org.jalcedo.babel.database/trunk/models/babel/translation.rb

    r1342 r1344  
    11 
    22module Babel 
     3 
    34class Translation < ActiveRecord::Base 
    45  set_primary_key 'translation_id' 
     
    89  belongs_to :user, :foreign_key => "userid" 
    910   
     11  validates_presence_of :value 
     12   
    1013  def validate_on_create 
    1114    return unless active_translation = Translation.find(:first, 
    12       :conditions => ['string_id and language_id and is_active', string_id, language_id, 1] 
     15      :conditions => ['string_id = ? and language_id = ? and is_active = ?', string_id, language_id, 1] 
     16      # XXX cant specify this bug. 
     17      # :conditions => ['string_id and language_id and is_active', string_id, language_id, 1] 
    1318    ) 
     19    #puts "#{active_translation.value}, #{value}, #{active_translation.string_id}, #{string_id}" 
    1420    if active_translation.value == value 
    1521      errors.add(:value, 'Same value on active translation.') 
  • org.jalcedo.babel.database/trunk/spec/babel/translation_spec.rb

    r1341 r1344  
    1212   
    1313  before(:each) do 
    14     @translation = create_translation 'ファイル' 
    15     @translation.save! 
    1614  end 
    1715   
     
    2119 
    2220  it 'should new translation is active.' do 
     21    @translation = create_translation 'ファイル' 
     22    @translation.save! 
    2323    @translation.is_active.should == 1 
     24  end 
     25   
     26  it 'should not save empty value file.' do 
     27    @translation = create_translation '' 
     28    lambda { @translation.save! }.should raise_error 
     29  end 
     30   
     31  it 'should not save nil value file.' do 
     32    @translation = create_translation nil 
     33    lambda { @translation.save! }.should raise_error 
    2434  end 
    2535end 
     
    5868   
    5969  before(:all) do 
     70    @other_translation = create_translation 'へんしゅー' 
     71    @other_translation.string = Babel::String.find_by_value('Edit') 
     72    @other_translation.save! 
     73     
    6074    # old old is not in_active 
    6175    @old_old_translation = create_translation 'ヘルプ' 
     
    6579    @old_translation = create_translation 'ヘルプププ' 
    6680    @old_translation.save! 
     81     
     82    @other_translation = create_translation '編集' 
     83    @other_translation.string = Babel::String.find_by_value('Edit') 
     84    @other_translation.save! 
    6785  end 
    6886   
     
    7492    @translation = create_translation 'ヘルプププ' 
    7593    lambda { @translation.save! }.should raise_error 
     94    @translation = create_translation '編集' 
     95    @translation.string = Babel::String.find_by_value('Edit') 
     96    lambda { @translation.save! }.should raise_error 
     97  end 
     98   
     99  it 'should register same value for another strings.' do 
     100    @translation = create_translation 'ファイル' 
     101    lambda { @translation.save! }.should_not raise_error 
    76102  end 
    77103