This commit is contained in:
Devin Howard 2015-12-17 09:16:02 +08:00
parent 2525a6fb65
commit 696bac17e6
4 changed files with 17 additions and 2 deletions

View file

@ -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/

7
spec/factories/maps.rb Normal file
View file

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :map do
name { random_string(10) }
permission :commons
user
end
end

View file

@ -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

View file

@ -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