I am using Rails 2.3.2 and Ruby 1.8.7, the latest stable combination
recommended by rubyonrails.org.
I am continuing to troubleshoot this. I have deleted all the sample
data that I preloaded so that my database is empty. Now, the opposite
is happening, it is letting me create records in violation of the
uniqueness validation:
I check the database and yes it contains both of the above identical
records. Only their :Stat_ids are different. Something wrong with my
uniqueness validation?
I haven't been able to reproduce the issue that you have been having
(on 2.3.2). I created a test suite for your model. Can you run that to
see if you get the same problem.
Note that I changed the attribute name "aspect" to "score_aspect"
Below are the errors. Thank you for your help.
ruby test/unit/stat_test2.rb
Loaded suite test/unit/stat_test2
Started
E...EEEE
Finished in 1.227252 seconds.
1) Error:
test_should_add_error_on_score_aspect_when_validating_with_the_same_score_aspect
(StatTest):
ActiveRecord::RecordInvalid: Validation failed: Score aspect has
already been taken
test/unit/stat_test2.rb:33:in
`test_should_add_error_on_score_aspect_when_validating_with_the_same_score_aspect'
2) Error:
test_should_not_add_error_on_score_aspect_when_validating_an_updated_stat
(StatTest):
ActiveRecord::RecordInvalid: Validation failed: Score aspect has
already been taken
test/unit/stat_test2.rb:41:in
`test_should_not_add_error_on_score_aspect_when_validating_an_updated_stat'
3) Error:
test_should_not_add_error_on_score_aspect_when_validating_with_a_different_score_aspect
(StatTest):
ActiveRecord::RecordInvalid: Validation failed: Score aspect has
already been taken
test/unit/stat_test2.rb:25:in
`test_should_not_add_error_on_score_aspect_when_validating_with_a_different_score_aspect'
4) Error:
test_should_score_aspect_be_read_only(StatTest):
ActiveRecord::RecordInvalid: Validation failed: Score aspect has
already been taken
test/unit/stat_test2.rb:49:in
`test_should_score_aspect_be_read_only'
5) Error:
test_should_user_be_read_only(StatTest):
ActiveRecord::RecordInvalid: Validation failed: Score aspect has
already been taken
test/unit/stat_test2.rb:57:in `test_should_user_be_read_only'
Well you have me stumped, I ran your test suite against mine (after
modifying the data structure) and it works. I'm assuming there is
something in the mix that I'm not aware of. I'm not sure if it's much
help, but you can download my test app to see if that runs for you.