This is part of the Chores series of posts.
I’m now attacking the Idenitity model. My idea for this is a model that contains a single field. That field is a valid, properly formatted, immutable OpenID. Because I’m going to need to validate OpenIDs I’m going to install the Open ID Plugin as follows.
$ ruby script/plugin install git://github.com/rails/open_id_authentication.git Initialized empty Git repository in c:/rails/chores/vendor/plugins/open_id_authentication/.git/ remote: Counting objects: 35, done.←[K remote: Compressing objects: 100% (31/31), done.←[K remote: Total 35 (delta 4), reused 21 (delta 2)←[K Unpacking objects: 100% (35/35), done. From git://github.com/rails/open_id_authentication * branch HEAD -> FETCH_HEAD
$ rake open_id_authentication:db:create (in c:/rails/chores) exists db/migrate create db/migrate/20090125184610_add_open_id_authentication_tables.rb
$ rake db:migrate (in c:/rails/chores) == AddOpenIdAuthenticationTables: migrating ================================== -- create_table(:open_id_authentication_associations, {:force=>true}) -> 0.0310s -- create_table(:open_id_authentication_nonces, {:force=>true}) -> 0.0160s == AddOpenIdAuthenticationTables: migrated (0.0470s) =========================
Here is my test for the Identity model
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 | require 'test_helper' class IdentityShouldBeValidatedTest < ActiveSupport::TestCase specify "that an open ID is required on create" do identity = Identity.new invalid identity identity.open_id = "test.example.com" valid identity end specify "message for an overly long identifier" do identity = Identity.new :identifier => hundred_and_one_character_identifier validation_message_for identity, :identifier, "is too long." end specify "message for a null identifier" do identity = Identity.new validation_message_for identity, :identifier, "can not be blank." end specify "message for a poorly formatted" do identity = Identity.new :identifier => invalid_open_id validation_message_for identity, :identifier, "is not a valid Open ID." end specify "message for a duplicate identifier" do Identity.make :identifier => valid_identifier identity = Identity.new :identifier => valid_identifier validation_message_for identity, :identifier, "is already in use, please use another." end specify "that 100 character identifier is valid" do identity = Identity.new :identifier => hundred_character_identifier valid identity end specify "that identifier is unique" do Identity.make :identifier => valid_identifier identity = Identity.new :identifier => valid_identifier invalid identity end specify "that open_id must have the correct format" do identity = Identity.new identity.open_id = invalid_open_id invalid identity end specify "that open_id uniqueness extends to identifier when validated" do Identity.make :identifier => valid_identifier identity = Identity.new :open_id => "test.example.com" invalid identity end protected def hundred_character_identifier "http://This.is.a.hundred.character.description.one.hundred.chatacters.is.not.too.long.but.it.of.com/" end def hundred_and_one_character_identifier "http://This.is.a.hundred1.character.description.one.hundred.chatacters.is.not.too.long.but.it.of.com/" end def invalid_open_id "bad_id" end end class IdentityOpenIdShouldSetIdentifierTest < ActiveSupport::TestCase specify "that open_id sets identifier" do identity = Identity.new assert_nil identity.identifier identity.open_id = "test.example.com" assert_not_nil identity.identifier end specify "that identifier sets open_id" do identity = Identity.new assert_nil identity.open_id identity.identifier = "http://test.example.com/" assert_not_nil identity.open_id end specify "that open_id is nicely formatted for display" do identity = Identity.new :identifier => "http://test.example.com/" assert_equal valid_open_id, identity.open_id end end class IdentityShouldBeImmutableTest < ActiveSupport::TestCase specify "that open_id is immutable" do identity = Identity.make assert_raise RuntimeError do identity.open_id = "monkey.example.com" end end specify "that identifier is immutable" do identity = Identity.make assert_raise RuntimeError do identity.identifier = "http://monkey.example.com/" end end end class IdentityShouldBeFoundByOpenID < ActiveSupport::TestCase specify "that open_id can be used to find a record" do identity = Identity.make :identifier => valid_identifier identity_from_db = Identity.find_by_open_id valid_open_id assert_equal identity.identifier, identity.identifier end specify "that display formatted open_id can be used to find a record" do identity = Identity.make :identifier => valid_identifier identity_from_db = Identity.find_by_open_id valid_identifier assert_equal identity.identifier, identity.identifier end end |
Here is the code that passes the test
./test/test_helper.rb
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 | ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require File.expand_path(File.dirname(__FILE__) + "/blueprints") require 'test_help' require 'faker' class ActiveSupport::TestCase self.use_transactional_fixtures = true self.use_instantiated_fixtures = false def invalid model assert !model.valid? end def valid model assert model.valid? end def validation_message_for model, column, message invalid model assert_equal message, model.errors.on(column) end def valid_identifier "http://test.example.com/" end def valid_open_id "test.example.com" end end def specify *args, &block test(*args, &block) end |
./app/models/identity.rb
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 | class Identity < ActiveRecord::Base include OpenIdAuthentication validates_presence_of :identifier, :message => "can not be blank." validates_uniqueness_of :identifier, :message => "is already in use, please use another." validates_length_of :identifier, :maximum => 100, :allow_nil => true, :message => "is too long." validate_on_create :valid_id def open_id return nil if self.identifier.nil? self.identifier[7..-2] end def identifier= identifier raise "Cannot update identifier." unless new_record? set_identifier identifier end def open_id= open_id raise "Cannot update open_id." unless new_record? set_identifier open_id end def valid_id errors.add(:identifier, "is not a valid Open ID.") if @invalid_id end def self.find_by_open_id open_id id = OpenIdAuthentication::normalize_identifier(open_id) find_by_identifier open_id end protected def normalize_id id begin identifier = normalize_identifier(id) rescue OpenIdAuthentication::InvalidOpenId identifier = id @invalid_id = true end identifier end def set_identifier id write_attribute(:identifier, normalize_id(id)) end end |
./test/blueprints.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | require 'machinist' # if you installed machinist from gem Chore.blueprint do description "Put the dirty clothes in the hamper" end Identity.blueprint do identifier "http://#{Faker::Name.first_name}.#{Faker::Internet.domain_name}/" end Child.blueprint do child { Identity.make } parent { Identity.make } end |
This one took a little work to do and I’m going to revisit it in a little while to see if it needs any refactoring.
Tags: Chores
I’m ending up with 25 tests, 13 assertions, 0 failures, 19 errors ==> Ouch on the last one!
1) Error:
test_message_for_a_null_identity(ChildShouldBeValidated):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `method_missing’
test/blueprints.rb:6
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `instance_eval’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `run’
faker (0.3.1) lib/extensions/object.rb:3:in `returning’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist/active_record.rb:69:in `make’
/test/unit/child_test.rb:20:in `test_message_for_a_null_identity’
2) Error:
test_message_for_a_null_parent(ChildShouldBeValidated):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `method_missing’
test/blueprints.rb:6
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `instance_eval’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `run’
faker (0.3.1) lib/extensions/object.rb:3:in `returning’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist/active_record.rb:69:in `make’
/test/unit/child_test.rb:25:in `test_message_for_a_null_parent’
3) Error:
test_that_a_child_is_required(ChildShouldBeValidated):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `method_missing’
test/blueprints.rb:6
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `instance_eval’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `run’
faker (0.3.1) lib/extensions/object.rb:3:in `returning’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist/active_record.rb:69:in `make’
/test/unit/child_test.rb:13:in `test_that_a_child_is_required’
4) Error:
test_that_a_parent_is_required(ChildShouldBeValidated):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `method_missing’
test/blueprints.rb:6
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `instance_eval’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `run’
faker (0.3.1) lib/extensions/object.rb:3:in `returning’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist/active_record.rb:69:in `make’
/test/unit/child_test.rb:6:in `test_that_a_parent_is_required’
5) Error:
test_that_identifier_sets_open_id(IdentityOpenIdShouldSetIdentifierTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
/test/unit/identity_test.rb:81:in `test_that_identifier_sets_open_id’
6) Error:
test_that_open_id_is_nicely_formatted_for_display(IdentityOpenIdShouldSetIdentifierTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
/test/unit/identity_test.rb:86:in `new’
/test/unit/identity_test.rb:86:in `test_that_open_id_is_nicely_formatted_for_display’
7) Error:
test_that_open_id_sets_identifier(IdentityOpenIdShouldSetIdentifierTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:26:in `open_id=’
/test/unit/identity_test.rb:74:in `test_that_open_id_sets_identifier’
test_that_display_formatted_open_id_can_be_used_to_find_a_record(IdentityShouldBeFoundByOpenID):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:27:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:27:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:26:in `each’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:26:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `new’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist/active_record.rb:69:in `make’
/test/unit/identity_test.rb:115:in `test_that_display_formatted_open_id_can_be_used_to_find_a_record’
9) Error:
test_that_open_id_can_be_used_to_find_a_record(IdentityShouldBeFoundByOpenID):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:27:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:27:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:26:in `each’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:26:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `new’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist/active_record.rb:69:in `make’
/test/unit/identity_test.rb:109:in `test_that_open_id_can_be_used_to_find_a_record’
10) Error:
test_that_identifier_is_immutable(IdentityShouldBeImmutableTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `method_missing’
test/blueprints.rb:6
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `instance_eval’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `run’
faker (0.3.1) lib/extensions/object.rb:3:in `returning’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist/active_record.rb:69:in `make’
/test/unit/identity_test.rb:100:in `test_that_identifier_is_immutable’
11) Error:
test_that_open_id_is_immutable(IdentityShouldBeImmutableTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:50:in `method_missing’
test/blueprints.rb:6
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `instance_eval’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:19:in `run’
faker (0.3.1) lib/extensions/object.rb:3:in `returning’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist/active_record.rb:69:in `make’
/test/unit/identity_test.rb:93:in `test_that_open_id_is_immutable’
12) Error:
test_message_for_a_duplicate_identifier(IdentityShouldBeValidatedTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:27:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:27:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:26:in `each’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:26:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `new’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist/active_record.rb:69:in `make’
/test/unit/identity_test.rb:27:in `test_message_for_a_duplicate_identifier’
13) Error:
test_message_for_a_poorly_formatted(IdentityShouldBeValidatedTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
/test/unit/identity_test.rb:22:in `new’
/test/unit/identity_test.rb:22:in `test_message_for_a_poorly_formatted’
14) Error:
test_message_for_an_overly_long_identifier(IdentityShouldBeValidatedTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
/test/unit/identity_test.rb:12:in `new’
/test/unit/identity_test.rb:12:in `test_message_for_an_overly_long_identifier’
15) Error:
test_that_100_character_identifier_is_valid(IdentityShouldBeValidatedTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
/test/unit/identity_test.rb:33:in `new’
/test/unit/identity_test.rb:33:in `test_that_100_character_identifier_is_valid’
16) Error:
test_that_an_open_ID_is_required_on_create(IdentityShouldBeValidatedTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:26:in `open_id=’
/test/unit/identity_test.rb:7:in `test_that_an_open_ID_is_required_on_create’
17) Error:
test_that_identifier_is_unique(IdentityShouldBeValidatedTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:27:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:27:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:26:in `each’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:26:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `new’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist/active_record.rb:69:in `make’
/test/unit/identity_test.rb:38:in `test_that_identifier_is_unique’
18) Error:
test_that_open_id_must_have_the_correct_format(IdentityShouldBeValidatedTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:26:in `open_id=’
/test/unit/identity_test.rb:45:in `test_that_open_id_must_have_the_correct_format’
19) Error:
test_that_open_id_uniqueness_extends_to_identifier_when_validated(IdentityShouldBeValidatedTest):
NameError: uninitialized constant OpenIdAuthentication::InvalidOpenId
app/models/identity.rb:42:in `normalize_id’
app/models/identity.rb:50:in `set_identifier’
app/models/identity.rb:21:in `identifier=’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:27:in `send’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:27:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:26:in `each’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:26:in `initialize’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `new’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist.rb:17:in `run’
C:/ruby/lib/ruby/gems/1.8/gems/notahat-machinist-0.3.1/lib/machinist/active_record.rb:69:in `make’
/test/unit/identity_test.rb:50:in `test_that_open_id_uniqueness_extends_to_identifier_when_validated’
It looks like your app is not finding the OpenIdAuthentication plugin. Do you have anything in vendor/plugins?
Hi Jamal,
Thanks for your response. Yes. under my .vendor/plugins I have the open_id_authentication folder with a lib and tasks folder and 4 other files. I ran the rake open_id_authentication:db:create and it ran OK, and then I did the rake db:migrate but it created one extra table compared to your results. “open_id_authentication_nonces”
Here’s the migration —
class AddOpenIdAuthenticationTables true do |t|
t.column “server_url”, :binary
t.column “handle”, :string
t.column “secret”, :binary
t.column “issued”, :integer
t.column “lifetime”, :integer
t.column “assoc_type”, :string
end
create_table “open_id_authentication_nonces”, :force => true do |t|
t.column “nonce”, :string
t.column “created”, :integer
end
create_table “open_id_authentication_settings”, :force => true do |t|
t.column “setting”, :string
t.column “value”, :binary
end
end
def self.down
drop_table “open_id_authentication_associations”
drop_table “open_id_authentication_nonces”
drop_table “open_id_authentication_settings”
end
end
Jamal,
I see there’s an error in my identity.rb model:
def self.find_by_open_id open_id
id = OpenIdAuthentication::normalize_identifier(open_id)
find_by_identifier open_id
end
RadRails is suggesting I clean up my unused code in the line id = OpenIdAuthentication::normalize_identifier(open_id)
Jamal,
Do I need to add
map.resources :identities
to my routes.rb?
Sorry for my ignorance,
Wayne
Hi Wayne,
I’m not sure what is causing the issue you are running into. What version of rails are you running? Look in config/environment.rb. There should be a line that starts with RAILS_GEM_VERSION =
2.3.2
Thanks, I’ll run back through this and see what I may have missed, or what may have changed since I wrote this.
Jamal,
You rock! Thanks so much. I think you’re work is really major contribution to BDD. I’ve also been researching OpenIDAuthentication to see different implementations. I’ve tried adding various controllers, models and views to see if I can get any more tests to pass, but so far I can’t even get one more.
Thanks again,
Wayne
Wayne, out of curiosity, does it work if you run script/server?
I think so. Here’s my results:
=> Booting Mongrel
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Jamal,
Do you think I should put some ‘require…’ statements in anywhere to force load some of the required classes? (I’m wondering if even though everything is in my environment, it isn’t getting loaded?)
Wayne
Nice looking blog you have here. The theme is awesome, great color combination.
Thanks, it’s called RenownedMint by RenownedMedia