diff --git a/app/models/map.rb b/app/models/map.rb index e5c483f1..48dcae3b 100644 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -17,7 +17,7 @@ class Map < ActiveRecord::Base validates :arranged, presence: true validates :arranged, inclusion: { in: [true, false] } validates :permission, presence: true - validates :permission, inclusion: { in: Perm::ISSIONS } + validates :permission, inclusion: { in: Perm::ISSIONS.map(&:to_s) } # Validate the attached image is image/jpg, image/png, etc validates_attachment_content_type :screenshot, :content_type => /\Aimage\/.*\Z/ diff --git a/spec/factories/maps.rb b/spec/factories/maps.rb new file mode 100644 index 00000000..74058605 --- /dev/null +++ b/spec/factories/maps.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :map do + name { random_string(10) } + permission :commons + user + end +end diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index 8a83947e..b0590edb 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -1,5 +1,11 @@ require 'rails_helper' RSpec.describe Map, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + # TODO: what is it important to be sure about when working with a Map? + it { is_expected.to belong_to :user } + it { is_expected.to validate_presence_of :name } + it { is_expected.to validate_presence_of :arranged } + it { is_expected.to validate_presence_of :permission } + it { is_expected.to validate_inclusion_of(:permission).in_array Perm::ISSIONS.map(&:to_s) } end + diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 17c04cd7..23f21101 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -40,4 +40,6 @@ RSpec.configure do |config| config.include Devise::TestHelpers, type: :controller config.include ControllerHelpers, type: :controller + config.include Shoulda::Matchers::ActiveModel, type: :model + config.include Shoulda::Matchers::ActiveRecord, type: :model end