diff --git a/app/models/paper.rb b/app/models/paper.rb index 0cbf551..2d94c38 100644 --- a/app/models/paper.rb +++ b/app/models/paper.rb @@ -5,8 +5,7 @@ class Paper < ActiveRecord::Base include Elasticsearch::Model include Elasticsearch::Model::Callbacks - validates_presence_of :body, :content, :name, :originator, :paper_type, :reference, :url - validates_presence_of :published_at, allow_nil: true + validates_presence_of :body, :content, :name , :originator, :paper_type, :reference, :url, :published_at validates :url, uniqueness: true settings index: { number_of_shards: 1 } do @@ -17,7 +16,7 @@ class Paper < ActiveRecord::Base indexes :paper_type, type: :string, index: :not_analyzed indexes :originator, type: :string, index: :not_analyzed end - end + end def split_originator originator.split(/\d\.\s/).reject {|s| s.blank?} || originator diff --git a/test/models/paper_test.rb b/test/models/paper_test.rb new file mode 100644 index 0000000..8354fbe --- /dev/null +++ b/test/models/paper_test.rb @@ -0,0 +1,16 @@ +require 'test_helper' + +class PaperTest < ActiveSupport::TestCase + + context "Validations" do + should validate_presence_of(:body) + should validate_presence_of(:content) + should validate_presence_of(:name) + should validate_presence_of(:originator) + should validate_presence_of(:paper_type) + should validate_presence_of(:reference) + should validate_presence_of(:url) + should validate_presence_of(:published_at) + end + +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 1b94761..8a6e923 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,7 +5,7 @@ require 'capybara/rails' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all + # fixtures :all # Add more helper methods to be used by all tests here... end