Changeset 1341

Show
Ignore:
Timestamp:
02/13/08 14:21:30 (1 year ago)
Author:
yuanying
Message:

refactored specs (added helper).

Files:

Legend:

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

    r1337 r1341  
    1212end 
    1313 
    14 $:.unshift "#{APP_ROOT}/models" 
     14$:.unshift File.join(APP_ROOT, 'models') 
     15$:.unshift File.join(APP_ROOT, 'spec', 'helper') if ENV["APP_ENV"] == 'test' 
    1516 
    1617ActiveRecord::Base.establish_connection(DATABASE_CONFIG[ENV["APP_ENV"]]) 
  • org.jalcedo.babel.database/trunk/models/babel/register.rb

    r1340 r1341  
    33   
    44  class Register 
    5     def initialize project, version, username 
     5    def initialize project, version, username, language_iso 
     6       
     7    end 
     8     
     9    def register 
    610       
    711    end 
  • org.jalcedo.babel.database/trunk/models/babel/string.rb

    r1337 r1341  
    33class String < ActiveRecord::Base 
    44  set_primary_key 'string_id' 
     5  belongs_to :file, :foreign_key => 'file_id' 
    56end 
    67end 
  • org.jalcedo.babel.database/trunk/models/babel/translation.rb

    r1338 r1341  
    77  belongs_to :language, :foreign_key => "language_id" 
    88  belongs_to :user, :foreign_key => "userid" 
     9   
     10  def before_create 
     11    Translation.update_all('is_active = 0', "string_id = #{string_id} and language_id = #{language_id}") 
     12  end 
    913end 
    1014end 
  • org.jalcedo.babel.database/trunk/spec/babel/language_spec.rb

    r1336 r1341  
    44describe Babel::Language do 
    55   
    6   it 'should have at lease one language.' do 
     6  it 'should have at least one language.' do 
    77    Babel::Language.count.should > 0 
    88  end 
  • org.jalcedo.babel.database/trunk/spec/babel/register_spec.rb

    r1340 r1341  
    44 
    55describe Babel::Register do 
     6  describe 'when language is not inputted.' do 
     7    it 'should raise error.' do  
     8      lambda { Babel::Register.new('eclipse', '3.3', 'babel@eclipse.org', nil) }.should raise_error(ArgumentError) 
     9    end 
     10  end 
     11   
    612  describe 'when user is not inputted.' do 
    713    it 'should raise error.' do  
    8       lambda { Babel::Register.new('eclipse', '3.3', nil) }.should raise_error(ArgumentError) 
     14      lambda { Babel::Register.new('eclipse', '3.3', nil, 'ja') }.should raise_error(ArgumentError) 
    915    end 
    1016  end 
     
    1218  describe 'when project is not inputted.' do 
    1319    it 'should raise error.' do 
    14       lambda { Babel::Register.new(nil, '3.3', 'babel@eclipse.org') }.should raise_error(ArgumentError) 
     20      lambda { Babel::Register.new(nil, '3.3', 'babel@eclipse.org', 'ja') }.should raise_error(ArgumentError) 
    1521    end 
    1622  end 
     
    1824  describe 'when version is not inputted.' do 
    1925    it 'should raise error.' do 
    20       lambda { Babel::Register.new('eclipse', nil, 'babel@eclipse.org') }.should raise_error(ArgumentError) 
     26      lambda { Babel::Register.new('eclipse', nil, 'babel@eclipse.org', 'ja') }.should raise_error(ArgumentError) 
     27    end 
     28  end 
     29   
     30  describe 'when language is not exist' do 
     31    it 'should raise error.' do 
     32      lambda { Babel::Register.new('eclipse', '3.3', 'babel@eclipse.org', 'arteoijoeroejo') }.should raise_error(ArgumentError) 
    2133    end 
    2234  end 
     
    2436  describe 'when user is not exist' do 
    2537    it 'should raise error.' do 
    26       lambda { Babel::Register.new('eclipse', '3.3', 'ziaehtiier!!7yrw') }.should raise_error(ArgumentError) 
     38      lambda { Babel::Register.new('eclipse', '3.3', 'ziaehtiier!!7yrw', 'ja') }.should raise_error(ArgumentError) 
    2739    end 
    2840  end 
     
    3042  describe 'when project is not exist' do 
    3143    it 'should raise error.' do 
    32       lambda { Babel::Register.new('oaaejtghe4389u**', '3.3', 'babel@eclipse.org') }.should raise_error(ArgumentError) 
     44      lambda { Babel::Register.new('oaaejtghe4389u**', '3.3', 'babel@eclipse.org', 'ja') }.should raise_error(ArgumentError) 
    3345    end 
    3446  end 
     
    3648  describe 'when version is not exist' do 
    3749    it 'should raise error.' do 
    38       lambda { Babel::Register.new('eclipse', '-00322.sssrr', 'babel@eclipse.org') }.should raise_error(ArgumentError) 
     50      lambda { Babel::Register.new('eclipse', '-00322.sssrr', 'babel@eclipse.org', 'ja') }.should raise_error(ArgumentError) 
    3951    end 
    4052  end 
     
    4254 
    4355describe Babel::Register, 'when register Japanease translations to Eclipse 3.3.' do 
     56  before(:all) do 
     57     @japanease = Babel::Language.find_by_iso_code('ja') 
     58  end 
    4459   
    45   it 'should increse Japanease translations on Eclipse 3.3 strings.' 
     60  after(:each) do 
     61    Babel::Translation.delete_all 
     62  end 
    4663   
    47   it 'should not increase other translations (French).' 
     64  it 'should increse Japanease translations on Eclipse 3.3 strings.' do 
     65    lambda { 
     66      Babel::Register.new('eclipse', '3.3', 'babel@eclipse.org', 'ja').register 
     67    }.should change{  
     68      Babel::Translation.count( 
     69        :conditions => ['files.project_id = ? and files.version = ?', 'eclipse', '3.3'], 
     70        :include => { :string => :file } 
     71      )  
     72    } 
     73  end 
    4874   
    49   it "should not increase other project version's translations (Eclipse 3.4). " 
     75  it 'should not increase other translations.' do 
     76    lambda { 
     77      Babel::Register.new('eclipse', '3.3', 'babel@eclipse.org', 'ja').register 
     78    }.should_not change{  
     79      Babel::Translation.count( 
     80        :conditions => ['files.project_id = ? and files.version = ? and translations.language_id <> ?', 'eclipse', '3.3', @japanease.id], 
     81        :include => { :string => :file } 
     82      )  
     83    } 
     84  end 
     85   
     86  it "should not increase other project version's translations. " do 
     87    lambda { 
     88      Babel::Register.new('eclipse', '3.3', 'babel@eclipse.org', 'ja').register 
     89    }.should_not change{  
     90      Babel::Translation.count( 
     91        :conditions => ['files.project_id = ? and files.version <> ?', 'eclipse', '3.3'], 
     92        :include => { :string => :file } 
     93      )  
     94    } 
     95  end 
    5096   
    5197end 
  • org.jalcedo.babel.database/trunk/spec/babel/translation_spec.rb

    r1339 r1341  
    55require 'babel/translation' 
    66 
     7require 'translation_helper' 
     8 
     9include TranslationHelper 
     10 
    711describe Babel::Translation, 'when translating to Japanease for the first time.' do 
    8  
    9   before(:all) do 
    10     @file_menu_string = Babel::String.find_by_value('File') 
    11     @japanease = Babel::Language.find_by_iso_code('ja') 
    12     @test_user = Babel::User.find_by_username('babel@eclipse.org') 
    13   end 
    1412   
    1513  before(:each) do 
    16     @translation = Babel::Translation.new 
    17     @translation.string = @file_menu_string 
    18     @translation.language = @japanease 
    19     @translation.user = @test_user 
    20     @translation.value = 'ファイル' 
     14    @translation = create_translation 'ファイル' 
    2115    @translation.save! 
    2216  end 
     
    3327describe Babel::Translation, 'when translating to Japanease for the second time or later.' do 
    3428   
    35   before(:all) do 
    36     @edit_menu_string = Babel::String.find_by_value('Edit') 
    37     @japanease = Babel::Language.find_by_iso_code('ja') 
    38     @test_user = Babel::User.find_by_username('babel@eclipse.org') 
    39      
    40     @old_translation = Babel::Translation.new 
    41     @old_translation.string = @edit_menu_string 
    42     @old_translation.language = @japanease 
    43     @old_translation.user = @test_user 
    44     @old_translation.value = 'へんしゅー' 
     29  before(:each) do 
     30    @old_translation = create_translation 'へんしゅー' 
    4531    @old_translation.save! 
    46      
    47     @translation = Babel::Translation.new 
    48     @translation.string = @edit_menu_string 
    49     @translation.language = @japanease 
    50     @translation.user = @test_user 
    51     @translation.value = '編集' 
    52     @translation.save! 
    5332  end 
    5433 
    55   after(:all) do 
     34  after(:each) do 
    5635    Babel::Translation.delete_all 
    5736  end 
    5837   
    5938  it 'should old translation is not active.' do 
     39    @translation = create_translation '編集' 
     40    @translation.save! 
    6041    @_old_translation = Babel::Translation.find_by_translation_id(@old_translation.translation_id) 
    6142    @_old_translation.is_active.should == 0 
     43  end 
     44   
     45  it 'should not change another translations is_active attribute.' do 
     46    @translation = create_translation '編集' 
     47    lambda { 
     48      @translation.save! 
     49    }.should_not change { 
     50      Babel::Translation.count( 
     51        :conditions => ['is_active = ? and string_id <> ?', 1, @translation.string_id] 
     52      ) 
     53    } 
    6254  end 
    6355end 
     
    6658   
    6759  before(:all) do 
    68     @help_menu_string = Babel::String.find_by_value('Help') 
    69     @japanease = Babel::Language.find_by_iso_code('ja') 
    70     @test_user = Babel::User.find_by_username('babel@eclipse.org') 
    71      
    72     @old_old_translation = Babel::Translation.new 
    73     @old_old_translation.string = @help_menu_string 
    74     @old_old_translation.language = @japanease 
    75     @old_old_translation.user = @test_user 
    76     @old_old_translation.is_active = 0 
    77     @old_old_translation.created_on = Time.now.last_month 
    78     @old_old_translation.value = 'ヘルプ' 
     60    # old old is not in_active 
     61    @old_old_translation = create_translation 'ヘルプ' 
    7962    @old_old_translation.save! 
    8063     
    81     @old_translation = Babel::Translation.new 
    82     @old_translation.string = @help_menu_string 
    83     @old_translation.language = @japanease 
    84     @old_translation.user = @test_user 
    85     @old_translation.is_active = 1 
    86     @old_old_translation.created_on = Time.now.last_year 
    87     @old_translation.value = 'ヘルプププ' 
     64    # old is in_active 
     65    @old_translation = create_translation 'ヘルプププ' 
    8866    @old_translation.save! 
    89      
    9067  end 
    9168   
     
    9572   
    9673  it 'should not register same value for active translation.' do 
    97     @translation = Babel::Translation.new 
    98     @translation.string = @help_menu_string 
    99     @translation.language = @japanease 
    100     @translation.user = @test_user 
    101     @translation.value = 'ヘルプププ' 
     74    @translation = create_translation 'ヘルプププ' 
    10275    lambda { @translation.save! }.should raise_error 
    10376  end 
    10477   
    10578  it 'should register same value for non active translation.' do 
    106     @translation = Babel::Translation.new 
    107     @translation.string = @help_menu_string 
    108     @translation.language = @japanease 
    109     @translation.user = @test_user 
    110     @translation.value = 'ヘルプ' 
     79    @translation = create_translation 'ヘルプ' 
    11180    lambda { @translation.save! }.should_not raise_error 
    11281  end