Skip to content

Instantly share code, notes, and snippets.

View ManickYoj's full-sized avatar

Nick Francisci ManickYoj

View GitHub Profile
RSpec.describe "BillingAddresses", type: :request do
describe "GET /billing_address/:id" do
let (:billing_address) { create(:billing_address, user_id: 123) }
it "returns http success" do
get "/billing_address/#{billing_address.id}"
expect(response).to have_http_status(:success)
end
end
# /config/environments/test.rb
Rails.application.configure do
# ...
# Disable the need to have a record on the other end of an association
config.active_record.belongs_to_required_by_default = false
# ...
end
class BillingAddress < ApplicationRecord
belongs_to :user, optional: true
end
RSpec.describe "BillingAddresses", type: :request do
describe "GET /billing_address/:id" do
let (:billing_address) { build(:billing_address, id: 123, user_id: 500) }
it "returns http success" do
allow(BillingAddress)
.to receive(:find)
.and_return(billing_address)
RSpec.describe "BillingAddresses", type: :request do
describe "GET /billing_address/:id" do
let (:billing_address) { create(:billing_address, user: user) }
let (:user) { create(:user, user_group: user_group) }
let (:user_group) { create(:user_group, company: company) }
let (:company) { create(:company) }
it "returns http success" do
get "/billing_address/#{billing_address.id}"
@ManickYoj
ManickYoj / belongs_to_failure_example.rb
Last active January 19, 2022 21:31
Example belongs_to
# == Schema Information
#
# Table name: billing_addresses
#
# id :integer not null, primary key
# user_id :integer not null
#
class BillingAddress < ApplicationRecord
belongs_to :user
end
@ManickYoj
ManickYoj / turbo_devise_controller.rb
Created January 9, 2022 03:55
Devise Turbo Controller for Rails 7 Setup
class TurboDeviseController < ApplicationController
class Responder < ActionController::Responder
def to_turbo_stream
controller.render(options.merge(formats: :html))
rescue ActionView::MissingTemplate => error
if get?
raise error
elsif has_errors? && default_action
render rendering_options.merge(formats: :html, status: :unprocessable_entity)
else
@ManickYoj
ManickYoj / turbo_devise_controller.rb
Last active January 22, 2024 12:04
Devise Turbo Controller for Rails 7 Setup
# app/controllers/turbo_devise_controller.rb
class TurboDeviseController < ApplicationController
class Responder < ActionController::Responder
def to_turbo_stream
controller.render(options.merge(formats: :html))
rescue ActionView::MissingTemplate => error
if get?
raise error
elsif has_errors? && default_action
@ManickYoj
ManickYoj / config\initializers\devise.rb
Last active January 9, 2022 03:54
Devise Config Changes for Rails 7
# /config/initializers/devise.rb
# Turbo doesn't work with devise by default.
# Keep tabs on https://github.com/heartcombo/devise/issues/5446 for a possible fix
# Fix from https://gorails.com/episodes/devise-hotwire-turbo
class TurboFailureApp < Devise::FailureApp
def respond
if request_format == :turbo_stream
redirect
else
public class Receiver : MonoBehaviour {
public Camera receiverCamera;
public GameObject[] listeners;
public void SendCommand(string cmd, object val = null) {
foreach (GameObject listener in listeners) {
listener.SendMessage(cmd, val, SendMessageOptions.DontRequireReceiver);
};
}
}