Issue Details (XML | Word | Printable)

Key: ACTIVERECORD_JDBC-78
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: psfblair
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
activerecord-jdbc

validates_uniqueness_of broken

Created: 01/Oct/09 02:15 PM   Updated: 10/Mar/11 05:30 AM   Resolved: 01/Oct/09 07:12 PM
Component/s: SQLite3
Affects Version/s: 0.9.1
Fix Version/s: 0.9.2

Time Tracking:
Not Specified

Environment:

JRuby 1.3.1, Rails 2.3.4


Tags:


 Description  « Hide

Trying to use validates_uniqueness_of :name in a model has no effect at all. It is possible to create and save several records with the same name! Seems as if the constructed sql-queries do not contain the actual field-string.

Example:

A query to a user model with unique :name would look like this
user_one.save

SELECT users.id FROM users WHERE (users.name = '')
INSERT INTO users (name, created_at, updated_at) VALUES('one', '2009-09-08 15:04:00', '2009-09-08 15:04:00')

(Bug originally filed by Michael Hier at http://www.mail-archive.com/jruby-extras-devel@rubyforge.org/msg01309.html . I don't see it refiled here so I'm refiling.)



Nick Sieger added a comment - 01/Oct/09 07:12 PM

It looks like we have tests to cover this in sqlite3 in 0.9.2, so please try this again when the release comes out.


jpshackelford added a comment - 10/Mar/11 04:53 AM

I have just reproduced this with jruby-1.5.6 and the following.

activerecord (3.0.4)
      activemodel (= 3.0.4)
      activesupport (= 3.0.4)
      arel (~> 2.0.2)
      tzinfo (~> 0.3.23)
    activerecord-jdbc-adapter (1.1.1)
    activerecord-jdbcmysql-adapter (1.1.1)
      activerecord-jdbc-adapter (= 1.1.1)
      jdbc-mysql (~> 5.1.0)
    activerecord-jdbcsqlite3-adapter (1.1.1)
      activerecord-jdbc-adapter (= 1.1.1)
      jdbc-sqlite3 (~> 3.6.0)

My test:

describe DatabaseDefinition do

  before(:each) do
    @dd_attributes = {:name => "MyDatabase", :url => "some_url://somewhere:3306/"}
  end

  it "should validate uniqueness of :name" do
    DatabaseDefinition.create!(@dd_attributes)
    database_definition = DatabaseDefinition.create(@dd_attributes)
    database_definition.should_not be_valid
    database_definition.errors[:url].should be_empty
    database_definition.errors[:name].should_not be_empty
  end
end

Test passes under ruby-1.8.7 but fails under jruby-1.5.6.


jpshackelford added a comment - 10/Mar/11 05:30 AM

This must be an environmental issue. I can no longer reproduce.

I omitted from last report:

jdbc-sqlite3 (3.6.14.2.056)
jdbc-sqlite3 (3.6.14.2.056-java)

Dropping the database and migrating did not appear to help. I switched to jruby-1.5.5 using RVM, bundle install, bundle exec db:drop clean, bundle exec rake, and tests pass. Switching back to jruby-1.5.6 and now bundle exec rake and tests pass.

This doesn't warrant additional investigation until I can come up a pattern for reproducing.