From fa3a725df92a9e81e17f42b31e814015c629a624 Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 26 Jan 2016 17:58:33 +0800 Subject: [PATCH] mapping spec --- app/models/mapping.rb | 7 +++++-- spec/models/mapping_spec.rb | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 318aa5cf..680dbf8a 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -4,10 +4,13 @@ class Mapping < ActiveRecord::Base scope :synapsemapping, -> { where(mappable_type: :Synapse) } belongs_to :mappable, polymorphic: true - belongs_to :map, :class_name => "Map", :foreign_key => "map_id" - belongs_to :user + + validates :xloc, presence: true + validates :yloc, presence: true + validates :map, presence: true + validates :mappable, presence: true def user_name self.user.name diff --git a/spec/models/mapping_spec.rb b/spec/models/mapping_spec.rb index 32d34796..54c72b88 100644 --- a/spec/models/mapping_spec.rb +++ b/spec/models/mapping_spec.rb @@ -1,5 +1,11 @@ require 'rails_helper' RSpec.describe Mapping, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + it { is_expected.to belong_to :user } + it { is_expected.to belong_to :map } + it { is_expected.to belong_to :mappable } + it { is_expected.to validate_presence_of :xloc } + it { is_expected.to validate_presence_of :yloc } + it { is_expected.to validate_presence_of :map } + it { is_expected.to validate_presence_of :mappable } end