Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 040612e316
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 126 lines (103 sloc) 3.152 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
# This test suite tests the actual versioning of versioned fields

require File.join( File.dirname(__FILE__), '..', 'test_helper' )
require 'active_record'

begin
  require 'globalize/model/active_record'
rescue MissingSourceFile
  puts "This plugin requires the Globalize2 plugin: http://github.com/joshmh/globalize2/tree/master"
  puts
  raise
end

require 'globalize2_versioning'

# Hook up model translation
ActiveRecord::Base.send :include, Globalize::Model::ActiveRecord::Translated
ActiveRecord::Base.send :include, Globalize::Model::ActiveRecord::Versioned

# Load Section model
require File.join( File.dirname(__FILE__), '..', 'data', 'post' )

class VersioningTest < ActiveSupport::TestCase
  def setup
    I18n.fallbacks.clear
    reset_db!
  end
  
  test 'versioned? method' do
    post = Post.new
    assert !post.versioned?
    section = Section.new
    assert section.versioned?
  end
  
  test 'new record version' do
    section = Section.create :content => 'foo'
    assert_equal 1, section.version
  end
    
  test 'subsequent version' do
    section = Section.create :content => 'foo'
    assert_equal 1, section.version
    section.content = 'bar'
    assert section.save
    assert_equal 2, section.version
    section.update_attribute(:content, 'baz')
    assert_equal 3, section.version
  end
  
  test 'current version' do
    section = Section.create :content => 'foo'
    assert_equal 1, section.version
    section.content = 'bar'
    assert section.save
    assert_equal 2, section.version
    section.update_attribute(:content, 'baz')
    assert_equal 3, section.version
    section.reload
    assert_equal 3, section.version
    assert_equal 'baz', section.content
  end
  
  test 'current version with locale switching' do
    I18n.locale = :de
    
    section = Section.create :content => 'foo (de)'
    assert_equal 1, section.globalize_translations.size
    
    section.update_attribute :content, 'bar (de)'
    assert_equal 2, section.globalize_translations.size

    assert_equal 2, section.version
    assert_equal 'bar (de)', section.content

    I18n.locale = :en
    section.update_attribute :content, 'foo'
    assert_equal 1, section.version
    section.update_attribute :content, 'bar'
    assert_equal 2, section.version
    section.update_attribute(:content, 'baz')
    assert_equal 3, section.version
    section.reload
    assert_equal 3, section.version

    I18n.locale = :de
    assert_equal 2, section.version
    assert_equal 'bar (de)', section.content
  end
  
  test 'save_version? on new record' do
    section = Section.new :content => 'foo'
    assert section.save_version?
  end

  test 'save_version?' do
    section = Section.create :content => 'foo'
    assert !section.save_version?
    section.title = 'bar'
    assert !section.save_version?
    section.content = 'baz'
    assert section.save_version?
  end

=begin
test 'revert_to' do
flunk
end
test 'revert_to!' do
flunk
end
test 'versions association' do
flunk
end
test 'save_version_on_create' do
flunk
end

test 'clone_versioned_model' do
flunk
end
=end
end
Something went wrong with that request. Please try again.