Sha256: 7e3d6d06b66e904ea71cc6ee513cc99a9cb566be0eb44d3aa666ea5b27ce1a9d

Contents?: true

Size: 1.29 KB

Versions: 84

Compression:

Stored size: 1.29 KB

Contents

require "spec_helper"

describe "Simple::SQL.duplicate" do
  let!(:users) { 1.upto(USER_COUNT).map { create(:user) } }

  let!(:source_ids) { SQL.all("SELECT id FROM users") }

  before do
    SQL.ask "UPDATE users SET created_at=created_at - interval '1 hour', updated_at=updated_at - interval '1 hour'"
  end

  it "does not fail on a non-existing user" do
    dupe_ids = SQL.duplicate "users", -1

    expect(dupe_ids.length).to eq(0)
    expect(SQL.ask("SELECT COUNT(*) FROM users")).to eq(USER_COUNT)
  end

  it "duplicates a single user" do
    dupe_ids = SQL.duplicate "users", source_ids.first

    expect(dupe_ids.length).to eq(1)
    expect(SQL.ask("SELECT COUNT(*) FROM users")).to eq(1 + USER_COUNT)
  end

  it "duplicates many users" do
    dupe_ids = SQL.duplicate "users", (source_ids + [ -10 ])

    expect(dupe_ids.length).to eq(2)
    expect(SQL.ask("SELECT COUNT(*) FROM users")).to eq(2 + USER_COUNT)
  end

  it "updates the timestamp columns" do
    source_id = source_ids.first
    dupe_ids = SQL.duplicate "users", source_ids.first
    dupe_id = dupe_ids.first

    source_timestamp = SQL.ask("SELECT updated_at FROM users WHERE id=$1", source_id)
    dupe_timestamp = SQL.ask("SELECT updated_at FROM users WHERE id=$1", dupe_id)

    expect(dupe_timestamp).to be > source_timestamp
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
simple-sql-0.5.37 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.36 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.35 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.34 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.33 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.32 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.31 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.30 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.29 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.28 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.27 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.26 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.25 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.24 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.23 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.22 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.21 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.20 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.19 spec/simple/sql/duplicate_spec.rb
simple-sql-0.5.18 spec/simple/sql/duplicate_spec.rb