Sha256: 83222d6846a924b0d55962efd14f7f66259c53ddecb8e428df9fd7d16599a1cf

Contents?: true

Size: 1.83 KB

Versions: 25

Compression:

Stored size: 1.83 KB

Contents

require File.expand_path('../test_helper', __FILE__)

describe ".synchronize" do
  let(:topics) { Generate(3, :topics) }
  let(:titles) { %w(one two three) }

  setup do
    # update records outside of ActiveRecord knowing about it
    Topic.connection.execute( "UPDATE #{Topic.table_name} SET title='#{titles[0]}_haha' WHERE id=#{topics[0].id}", "Updating record 1 without ActiveRecord" )
    Topic.connection.execute( "UPDATE #{Topic.table_name} SET title='#{titles[1]}_haha' WHERE id=#{topics[1].id}", "Updating record 2 without ActiveRecord" )
    Topic.connection.execute( "UPDATE #{Topic.table_name} SET title='#{titles[2]}_haha' WHERE id=#{topics[2].id}", "Updating record 3 without ActiveRecord" )
  end

  it "reloads data for the specified records" do
    Topic.synchronize topics

    actual_titles = topics.map(&:title)
    assert_equal "#{titles[0]}_haha", actual_titles[0], "the first record was not correctly updated"
    assert_equal "#{titles[1]}_haha", actual_titles[1], "the second record was not correctly updated"
    assert_equal "#{titles[2]}_haha", actual_titles[2], "the third record was not correctly updated"
  end

  it "the synchronized records aren't dirty" do
    # Update the in memory records so they're dirty
    topics.each { |topic| topic.title = 'dirty title' }

    Topic.synchronize topics

    assert_equal false, topics[0].changed?, "the first record was dirty"
    assert_equal false, topics[1].changed?, "the second record was dirty"
    assert_equal false, topics[2].changed?, "the third record was dirty"
  end

  it "ignores default scope" do
    # update records outside of ActiveRecord knowing about it
    Topic.connection.execute( "UPDATE #{Topic.table_name} SET approved='0' WHERE id=#{topics[0].id}", "Updating record 1 without ActiveRecord" )

    Topic.synchronize topics
    assert_equal false, topics[0].approved
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
activerecord-import-1.4.0 test/synchronize_test.rb
activerecord-import-1.3.0 test/synchronize_test.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/activerecord-import-1.2.0/test/synchronize_test.rb
activerecord-import-1.2.0 test/synchronize_test.rb
activerecord-import-1.1.0 test/synchronize_test.rb
activerecord-import-1.0.8 test/synchronize_test.rb
activerecord-import-1.0.7 test/synchronize_test.rb
activerecord-import-1.0.6 test/synchronize_test.rb
activerecord-import-1.0.5 test/synchronize_test.rb
activerecord-import-1.0.4 test/synchronize_test.rb
activerecord-import-1.0.3 test/synchronize_test.rb
activerecord-import-1.0.2 test/synchronize_test.rb
activerecord-import-1.0.1 test/synchronize_test.rb
activerecord-import-1.0.0 test/synchronize_test.rb
activerecord-import-0.28.2 test/synchronize_test.rb
activerecord-import-0.28.1 test/synchronize_test.rb
activerecord-import-0.28.0 test/synchronize_test.rb
activerecord-import-0.27.0 test/synchronize_test.rb
activerecord-import-0.26.0 test/synchronize_test.rb
activerecord-import-0.25.0 test/synchronize_test.rb