From cc99ed001d8318ee642ab68e55bf3ab247c83c6a Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 26 Jan 2016 18:42:24 +0800 Subject: [PATCH] fix mapping_controller_spec.rb --- app/controllers/mappings_controller.rb | 6 ------ app/models/mapping.rb | 2 +- spec/controllers/mappings_controller_spec.rb | 9 ++++----- spec/factories/mappings.rb | 5 +++++ spec/spec_helper.rb | 6 ------ spec/support/controller_helpers.rb | 8 ++++++++ 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/controllers/mappings_controller.rb b/app/controllers/mappings_controller.rb index 27567eb4..c20b0153 100644 --- a/app/controllers/mappings_controller.rb +++ b/app/controllers/mappings_controller.rb @@ -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 diff --git a/app/models/mapping.rb b/app/models/mapping.rb index 680dbf8a..425f358d 100644 --- a/app/models/mapping.rb +++ b/app/models/mapping.rb @@ -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 diff --git a/spec/controllers/mappings_controller_spec.rb b/spec/controllers/mappings_controller_spec.rb index b2568b51..ffc9bac9 100644 --- a/spec/controllers/mappings_controller_spec.rb +++ b/spec/controllers/mappings_controller_spec.rb @@ -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 diff --git a/spec/factories/mappings.rb b/spec/factories/mappings.rb index 479a3a16..bed0b754 100644 --- a/spec/factories/mappings.rb +++ b/spec/factories/mappings.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9cab52e4..842badd5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/support/controller_helpers.rb b/spec/support/controller_helpers.rb index 5fe34854..dc301e11 100644 --- a/spec/support/controller_helpers.rb +++ b/spec/support/controller_helpers.rb @@ -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