Skip to content

Commit

Permalink
Setup basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Andersson committed Feb 19, 2009
1 parent fd1c222 commit 7ccac99
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -8,6 +8,7 @@ task :default => :test
desc 'Test the model_translations plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
Expand Down
60 changes: 55 additions & 5 deletions test/model_translations_test.rb
@@ -1,8 +1,58 @@
require 'test/unit'
require 'test_helper'

class ModelTranslationsTest < Test::Unit::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")

def setup_db
ActiveRecord::Schema.define(:version => 1) do
create_table :posts do |t|
t.timestamps
end
create_table :post_translations do |t|
t.string :locale
t.references :post
t.string :title
t.text :text
t.timestamps
end
end
end

def teardown_db
ActiveRecord::Base.connection.tables.each do |table|
ActiveRecord::Base.connection.drop_table(table)
end
end

class Post < ActiveRecord::Base
translates :title, :text
end

class ModelTranslationsTest < ActiveSupport::TestCase
def setup
setup_db
I18n.locale = I18n.default_locale = :en
Post.create(:title => 'English title', :text => 'Text')
end

def teardown
teardown_db
end

test "database setup" do
assert Post.count == 1
end

test "allow translation" do
I18n.locale = :sv
Post.first.update_attribute :title, 'Svensk titel'
assert Post.first.title == 'Svensk titel'
I18n.locale = :en
assert Post.first.title == 'English title'
end

test "assert fallback to default" do
assert Post.first.title == 'English title'
I18n.locale = :sv
assert Post.first.title == 'English title'
end
end
3 changes: 3 additions & 0 deletions test/test_helper.rb
@@ -0,0 +1,3 @@
require 'rubygems'
require 'active_support'
require 'active_support/test_case'

0 comments on commit 7ccac99

Please sign in to comment.