fix mapping_controller_spec.rb
This commit is contained in:
parent
46013bc1b5
commit
cc99ed001d
6 changed files with 18 additions and 18 deletions
|
@ -15,8 +15,6 @@ class MappingsController < ApplicationController
|
||||||
def create
|
def create
|
||||||
@mapping = Mapping.new(mapping_params)
|
@mapping = Mapping.new(mapping_params)
|
||||||
|
|
||||||
@mapping.map.touch(:updated_at)
|
|
||||||
|
|
||||||
if @mapping.save
|
if @mapping.save
|
||||||
render json: @mapping, status: :created
|
render json: @mapping, status: :created
|
||||||
else
|
else
|
||||||
|
@ -28,8 +26,6 @@ class MappingsController < ApplicationController
|
||||||
def update
|
def update
|
||||||
@mapping = Mapping.find(params[:id])
|
@mapping = Mapping.find(params[:id])
|
||||||
|
|
||||||
@mapping.map.touch(:updated_at)
|
|
||||||
|
|
||||||
if @mapping.update_attributes(mapping_params)
|
if @mapping.update_attributes(mapping_params)
|
||||||
head :no_content
|
head :no_content
|
||||||
else
|
else
|
||||||
|
@ -44,8 +40,6 @@ class MappingsController < ApplicationController
|
||||||
|
|
||||||
@mapping.destroy
|
@mapping.destroy
|
||||||
|
|
||||||
@map.touch(:updated_at)
|
|
||||||
|
|
||||||
head :no_content
|
head :no_content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ class Mapping < ActiveRecord::Base
|
||||||
scope :synapsemapping, -> { where(mappable_type: :Synapse) }
|
scope :synapsemapping, -> { where(mappable_type: :Synapse) }
|
||||||
|
|
||||||
belongs_to :mappable, polymorphic: true
|
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
|
belongs_to :user
|
||||||
|
|
||||||
validates :xloc, presence: true
|
validates :xloc, presence: true
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe MappingsController, type: :controller do
|
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
|
before :each do
|
||||||
sign_in
|
sign_in
|
||||||
end
|
end
|
||||||
|
@ -38,15 +40,12 @@ RSpec.describe MappingsController, type: :controller do
|
||||||
|
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
context 'with valid params' do
|
context 'with valid params' do
|
||||||
let(:new_attributes) do
|
let(:new_attributes) { build(:mapping_random_location).attributes.except('id') }
|
||||||
skip('Add a hash of attributes valid for your model')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'updates the requested mapping' do
|
it 'updates the requested mapping' do
|
||||||
put :update,
|
put :update,
|
||||||
{ id: mapping.to_param, mapping: new_attributes }
|
{ id: mapping.to_param, mapping: new_attributes }
|
||||||
mapping.reload
|
mapping.reload
|
||||||
skip('Add assertions for updated state')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns the requested mapping as @mapping' do
|
it 'assigns the requested mapping as @mapping' do
|
||||||
|
|
|
@ -5,5 +5,10 @@ FactoryGirl.define do
|
||||||
map
|
map
|
||||||
user
|
user
|
||||||
association :mappable, factory: :topic
|
association :mappable, factory: :topic
|
||||||
|
|
||||||
|
factory :mapping_random_location do
|
||||||
|
xloc { rand(-100...100) }
|
||||||
|
yloc { rand(-100...100) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
require 'support/controller_helpers'
|
require 'support/controller_helpers'
|
||||||
require 'devise'
|
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.expect_with :rspec do |expectations|
|
config.expect_with :rspec do |expectations|
|
||||||
|
@ -9,9 +8,4 @@ RSpec.configure do |config|
|
||||||
config.mock_with :rspec do |mocks|
|
config.mock_with :rspec do |mocks|
|
||||||
mocks.verify_partial_doubles = true
|
mocks.verify_partial_doubles = true
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec.configure do |config|
|
|
||||||
config.include Devise::TestHelpers, type: :controller
|
|
||||||
config.extend ControllerHelpers, type: :controller
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
# https://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs
|
# https://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs
|
||||||
|
|
||||||
|
require 'devise'
|
||||||
|
|
||||||
module ControllerHelpers
|
module ControllerHelpers
|
||||||
# rubocop:disable Metrics/AbcSize
|
# rubocop:disable Metrics/AbcSize
|
||||||
def sign_in(user = create(:user))
|
def sign_in(user = create(:user))
|
||||||
|
@ -15,3 +18,8 @@ module ControllerHelpers
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/AbcSize
|
# rubocop:enable Metrics/AbcSize
|
||||||
end
|
end
|
||||||
|
|
||||||
|
RSpec.configure do |config|
|
||||||
|
config.include Devise::TestHelpers, :type => :controller
|
||||||
|
config.include ControllerHelpers, :type => :controller
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue