Skip to content

Commit

Permalink
Fix identifier spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Dec 5, 2013
1 parent 790c199 commit 79b94f2
Show file tree
Hide file tree
Showing 25 changed files with 101 additions and 55 deletions.
2 changes: 1 addition & 1 deletion app/models/identifier.rb
Expand Up @@ -5,7 +5,7 @@ class Identifier < ActiveRecord::Base
belongs_to :identifiable, polymorphic: :true
validates_presence_of :identifier, :identifiable_id, :identifiable_type, :type

before_validation: :validate_format_of_identifier
before_validation :validate_format_of_identifier

protected

Expand Down
3 changes: 2 additions & 1 deletion app/models/identifier/guid.rb
@@ -1,3 +1,4 @@
class Identifier::Guid < ActiveRecord::Base
class Identifier::Guid < Identifier


end
2 changes: 1 addition & 1 deletion app/models/identifier/guid/doi.rb
@@ -1,2 +1,2 @@
class Identifier::Guid::Doi < ActiveRecord::Base
class Identifier::Guid::Doi < Identifier::Guid
end
2 changes: 1 addition & 1 deletion app/models/identifier/guid/isbn.rb
@@ -1,2 +1,2 @@
class Identifier::Guid::Isbn < ActiveRecord::Base
class Identifier::Guid::Isbn < Identifier::Guid
end
2 changes: 1 addition & 1 deletion app/models/identifier/guid/issn.rb
@@ -1,2 +1,2 @@
class Identifier::Guid::Issn < ActiveRecord::Base
class Identifier::Guid::Issn < Identifier::Guid
end
2 changes: 1 addition & 1 deletion app/models/identifier/guid/lccn.rb
@@ -1,2 +1,2 @@
class Identifier::Guid::Lccn < ActiveRecord::Base
class Identifier::Guid::Lccn < Identifier::Guid
end
2 changes: 1 addition & 1 deletion app/models/identifier/guid/lsid.rb
@@ -1,2 +1,2 @@
class Identifier::Guid::Lsid < ActiveRecord::Base
class Identifier::Guid::Lsid < Identifier::Guid
end
2 changes: 1 addition & 1 deletion app/models/identifier/guid/orcid_id.rb
@@ -1,2 +1,2 @@
class Identifier::Guid::OrcidId < ActiveRecord::Base
class Identifier::Guid::OrcidId < Identifier::Guid
end
2 changes: 1 addition & 1 deletion app/models/identifier/guid/uri.rb
@@ -1,2 +1,2 @@
class Identifier::Guid::Uri < ActiveRecord::Base
class Identifier::Guid::Uri < Identifier::Guid
end
2 changes: 1 addition & 1 deletion app/models/identifier/guid/uuid.rb
@@ -1,2 +1,2 @@
class Identifier::Guid::Uuid < ActiveRecord::Base
class Identifier::Guid::Uuid < Identifier::Guid
end
2 changes: 1 addition & 1 deletion app/models/identifier/local_id.rb
@@ -1,2 +1,2 @@
class Identifier::LocalId < ActiveRecord::Base
class Identifier::LocalId < Identifier
end
2 changes: 1 addition & 1 deletion app/models/identifier/local_id/import_id.rb
@@ -1,2 +1,2 @@
class Identifier::LocalId::ImportId < ActiveRecord::Base
class Identifier::LocalId::ImportId < Identifier::LocalId
end
2 changes: 1 addition & 1 deletion app/models/identifier/local_id/trip_code.rb
@@ -1,2 +1,2 @@
class Identifier::LocalId::TripCode < ActiveRecord::Base
class Identifier::LocalId::TripCode < Identifier::LocalId
end
8 changes: 4 additions & 4 deletions app/models/user.rb
Expand Up @@ -5,15 +5,15 @@ class User < ActiveRecord::Base
# SEE: http://stackoverflow.com/questions/2049502/what-characters-are-allowed-in-email-address
# SEE: http://unicode-utils.rubyforge.org/

include Housekeeping::Users
# include Housekeeping::Users

before_validation { self.email = email.downcase }

VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
format: { with: VALID_EMAIL_REGEX } ,
uniqueness: { case_sensitive: true }
has_secure_password
validates :password, length: { minimum: 8 }
has_secure_password
validates :password, length: { minimum: 8 }

end
2 changes: 2 additions & 0 deletions config/environments/test.rb
Expand Up @@ -35,5 +35,7 @@
config.active_support.deprecation = :stderr


# Post scaffolding changes
require 'taxonworks'
I18n.enforce_available_locales = false
end
2 changes: 2 additions & 0 deletions db/seeds.rb
Expand Up @@ -20,5 +20,7 @@
when 'production'
# Never ever do anything. Production should be seeded with a Rake task or deploy script if need be.
when 'test'

# Never ever do anything. Test with FactoryGirl or inline.....

end
2 changes: 1 addition & 1 deletion lib/housekeeping/projects.rb
Expand Up @@ -12,7 +12,7 @@ module Housekeeping::Projects
belongs_to :project, inverse_of: related_instances

before_validation :set_project_id, on: :create
# validates :project, presence: true
validates :project, presence: true

before_save :prevent_alteration_in_other_projects
before_destroy :prevent_alteration_in_other_projects
Expand Down
2 changes: 0 additions & 2 deletions lib/housekeeping/users.rb
Expand Up @@ -6,10 +6,8 @@ module Housekeeping::Users
belongs_to :creator, foreign_key: :created_by_id, class_name: 'User'
belongs_to :updater, foreign_key: :updated_by_id, class_name: 'User'

=begin
validates :creator, presence: true
validates :updater, presence: true
=end

before_validation(on: :create) do
set_created_by_id
Expand Down
30 changes: 21 additions & 9 deletions spec/factories/bibtex_sources_factory.rb
@@ -1,14 +1,26 @@
FactoryGirl.define do
factory :bibtex_source, class: 'Source::Bibtex' do
end

factory :valid_bibtex_source, class: 'Source::Bibtex' do
bibtex_type 'article'
title 'article 1 just title'
end
factory :bibtex_source_base, class: Source::Bibtex do

ignore do

end

association :creator, factory: :valid_user, strategy: :build
association :updater, factory: :valid_user, strategy: :build
association :project, factory: :valid_project, strategy: :build

factory :bibtex_source, class: 'Source::Bibtex' do
end

factory :valid_bibtex_source, class: 'Source::Bibtex' do
bibtex_type 'article'
title 'article 1 just title'
end

factory :valid_bibtex_source_book_title_only, class: 'Source::Bibtex' do
bibtex_type 'book'
title 'valid book with just a title'
factory :valid_bibtex_source_book_title_only, class: 'Source::Bibtex' do
bibtex_type 'book'
title 'valid book with just a title'
end
end
end
14 changes: 11 additions & 3 deletions spec/factories/people_factory.rb
@@ -1,7 +1,15 @@
FactoryGirl.define do

factory :person_base, class: Person do
association :creator, factory: :valid_user
association :updater, factory: :valid_user

factory :person do
end

factory :valid_person do
last_name "Smith"
end
end
factory :valid_person, class: Person do
last_name "Smith"
end

end
13 changes: 8 additions & 5 deletions spec/factories/projects_factory.rb
@@ -1,11 +1,14 @@
# Read about factories at https://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :project do
name "MyString"
end

factory :valid_project, class: Project do
name "MyString"
factory :base_project, class: Project do
name 'My Project'

factory :project do
end

factory :valid_project do
end
end
end
33 changes: 23 additions & 10 deletions spec/factories/roles_factory.rb
@@ -1,19 +1,32 @@

FactoryGirl.define do
factory :role do
end

factory :source_author_role, class: SourceAuthor do
association :person, factory: :valid_person
association :role_object, factory: :valid_bibtex_source
end
factory :base_source_author_role, class: SourceAuthor do

factory :source_author_without_person, class: SourceAuthor do
association :role_object, factory: :valid_bibtex_source
end
ignore do
user
end

association :creator, factory: :valid_user, strategy: :build
association :updater, factory: :valid_user, strategy: :build
association :project, factory: :valid_project, strategy: :build

factory :source_author_role do
association :person, factory: :valid_person
association :role_object, factory: :valid_bibtex_source
end

factory :source_author_without_person do
association :role_object, factory: :valid_bibtex_source
end

factory :source_source_role do
association :person, factory: :valid_person
association :role_object, factory: :valid_human_source
end

factory :source_source_role, class: SourceSource do
association :person, factory: :valid_person
association :role_object, factory: :valid_human_source
end


Expand Down
6 changes: 1 addition & 5 deletions spec/models/identifier/guid_spec.rb
@@ -1,8 +1,7 @@
require 'spec_helper'

describe Identifier::Guid do

let(guid_identifier) {Idenfier::Guid.new}
let(:guid_identifier) {Idenfier::Guid.new}

context 'validation' do
context 'requires' do
Expand All @@ -18,7 +17,4 @@
expect(guid_identifier.errors.include?(:namespace)).to be_true
end




end
2 changes: 1 addition & 1 deletion spec/models/identifier/local_id_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Identifier::LocalId do
let(local_identifier) {Idenfier::LocalId.new}
let(:local_identifier) {Identifier::LocalId.new}

context 'validation' do
before(:each) {
Expand Down
15 changes: 13 additions & 2 deletions spec/models/user_spec.rb
Expand Up @@ -3,8 +3,8 @@
describe User do

let(:user) { User.new password: 'password',
password_confirmation: 'password',
email: 'user@example.com'}
password_confirmation: 'password',
email: 'user@example.com'}

subject { user }

Expand Down Expand Up @@ -37,4 +37,15 @@
it { should be_invalid }
end

context 'factory' do
let(:factory_user) {FactoryGirl.build(:valid_user)}
specify 'is valid' do
expect(factory_user.save).to be_true
end

specify 'login uses traits' do
expect(factory_user.email).to eq('default@example.com')
end
end

end

0 comments on commit 79b94f2

Please sign in to comment.