fix mapping_controller_spec.rb

This commit is contained in:
Devin Howard 2016-01-26 18:42:24 +08:00
parent 46013bc1b5
commit cc99ed001d
6 changed files with 18 additions and 18 deletions

View file

@ -15,8 +15,6 @@ class MappingsController < ApplicationController
def create
@mapping = Mapping.new(mapping_params)
@mapping.map.touch(:updated_at)
if @mapping.save
render json: @mapping, status: :created
else
@ -28,8 +26,6 @@ class MappingsController < ApplicationController
def update
@mapping = Mapping.find(params[:id])
@mapping.map.touch(:updated_at)
if @mapping.update_attributes(mapping_params)
head :no_content
else
@ -44,8 +40,6 @@ class MappingsController < ApplicationController
@mapping.destroy
@map.touch(:updated_at)
head :no_content
end

View file

@ -4,7 +4,7 @@ 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 :map, :class_name => "Map", :foreign_key => "map_id", touch: true
belongs_to :user
validates :xloc, presence: true

View file

@ -1,7 +1,9 @@
require 'rails_helper'
RSpec.describe MappingsController, type: :controller do
let(:mapping) { create(:mapping) }
let!(:mapping) { create(:mapping) }
let(:valid_attributes) { mapping.attributes.except('id') }
let(:invalid_attributes) { { xloc: 0 } }
before :each do
sign_in
end
@ -38,15 +40,12 @@ RSpec.describe MappingsController, type: :controller do
describe 'PUT #update' do
context 'with valid params' do
let(:new_attributes) do
skip('Add a hash of attributes valid for your model')
end
let(:new_attributes) { build(:mapping_random_location).attributes.except('id') }
it 'updates the requested mapping' do
put :update,
{ id: mapping.to_param, mapping: new_attributes }
mapping.reload
skip('Add assertions for updated state')
end
it 'assigns the requested mapping as @mapping' do

View file

@ -5,5 +5,10 @@ FactoryGirl.define do
map
user
association :mappable, factory: :topic
factory :mapping_random_location do
xloc { rand(-100...100) }
yloc { rand(-100...100) }
end
end
end

View file

@ -1,5 +1,4 @@
require 'support/controller_helpers'
require 'devise'
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
@ -9,9 +8,4 @@ RSpec.configure do |config|
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
RSpec.configure do |config|
config.include Devise::TestHelpers, type: :controller
config.extend ControllerHelpers, type: :controller
end
end

View file

@ -1,4 +1,7 @@
# https://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs
require 'devise'
module ControllerHelpers
# rubocop:disable Metrics/AbcSize
def sign_in(user = create(:user))
@ -15,3 +18,8 @@ module ControllerHelpers
end
# rubocop:enable Metrics/AbcSize
end
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
config.include ControllerHelpers, :type => :controller
end