Vanilla JS (the confirm method):
sinon.stub(window, 'confirm')
jQuery (the fadeOut method):
sinon.stub(jQuery.prototype, 'fadeOut')
A blog about the problems I've encountered while being a Ruby on Rails developer, and how I've solved them.
sinon.stub(window, 'confirm')
jQuery (the fadeOut method):
sinon.stub(jQuery.prototype, 'fadeOut')
def self.included(receiver)
if defined?(receiver.metadata) && receiver.metadata[:type] == :controller
receiver.send :include, Devise::TestHelpers
end
end
expect(content).to have_css("input[type='checkbox'][checked='checked']#rawr")
TypeError: nil is not a symbol nor a string
Oh no!!!! class BearHabitat < ActiveRecord::Base
self.primary_key = 'bear_id'
end
Now you should be able to update your model within your code with no problem. Why does this happen in the first place? My guess is that somewhere within ActiveModel, it assumes that the primary_key field is set. Since your migration set id to false, this value gets defaulted to nil. If you don't manually set it, ActiveModel gets sad. Now you can make ActiveModel happy again.
class CreateBearHabitats < ActiveRecord::Migration
def change
create_table :bear_habitats, id: false do |t| // prevents a default ID column from being created
t.belongs_to :bear, null: false //creates a bear_id column that can not be null
t.string :habitat
end
add_index :bear_habitats, :bear_id, unique: true // ensures that the bear_id column is unique
end
end
This BearHabitat model will now use bear_id as a primary key instead of the standard id.
// app/controllers/animals/bears_controller.rb
module Animals
class BearsController < ApplicationController
def index
// return all bears
end
end
end
// config/routes.rb
Animals::Engine.routes.draw do
get '/index' => 'bears#index'
end
// spec/dummy/config/routes.rb
Rails.application.routes.draw do
mount Animals::Engine => "/animals"
end
// spec/controllers/animals/bears_controller_spec.rb
RSpec.describe BearsController do
// this is the key line!
routes { Animals::Engine.routes }
describe 'GET :index' do
it 'does the thing' do
get :index
// test that all bears are returned
end
end
end