Skip to content

Instantly share code, notes, and snippets.

@taryneast
Created August 26, 2014 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taryneast/957d13ec70f65b262e78 to your computer and use it in GitHub Desktop.
Save taryneast/957d13ec70f65b262e78 to your computer and use it in GitHub Desktop.
Rails 4.0->4.1 failure
# Activate the gem you are reporting the issue against.
#gem 'activerecord', '~>4.0.0'
#gem 'activesupport', '~>4.0.0'
#gem 'activerecord', '~>4.0.0'
#gem 'railties', '~>4.0.0'
gem 'actionpack', '~>4.1.0'
gem 'activesupport', '~>4.1.0'
gem 'activerecord', '~>4.1.0'
gem 'railties', '~>4.1.0'
gem 'sqlite3'
gem 'multi_json'
gem 'tzinfo'
gem 'shoulda'
gem 'rspec-rails'
gem 'shoulda-matchers'
require 'active_record'
require 'logger'
require 'pry'
# rspec configuration
RSpec.configure do |config|
config.color_enabled = true
config.tty = true
config.formatter = :documentation
end
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :item_request_notifications do |t|
t.integer :notification_id
t.string :request
end
create_table :notifications do |t|
t.string :message_type
t.integer :recipient_id
end
create_table :users do |t|
t.string :name
end
end
class User < ActiveRecord::Base
has_many :notifications, :foreign_key => :recipient_id
end
class Notification < ActiveRecord::Base
belongs_to :recipient, :class_name => User.name, :inverse_of => :notifications, :touch => true
has_one :item_request_notification, :inverse_of => :notification, :dependent => :delete
validates :recipient, :presence => true
end
module NotificationMessage
extend ActiveSupport::Concern
included do
belongs_to :notification, :autosave => true, :inverse_of => name.underscore.to_sym, :dependent => :destroy
delegate :message_type, :recipient, :recipient=, :to => :notification
end
def notification
super || build_notification(:message_type => "whatever")
end
end
class ItemRequestNotification < ActiveRecord::Base
include NotificationMessage
validates :notification, :recipient, :presence => true
belongs_to :item_request, :inverse_of => :notifications
end
describe ItemRequestNotification do
let(:user) { User.create(:name => "Jane") }
describe "creation" do
subject(:irn) { ItemRequestNotification.create!(:recipient => user, :request => "whatever2") }
its(:recipient) { should == user }
its(:request) { should == "whatever2" }
its(:message_type) { should == 'whatever' }
its(:notification) { should_not be_nil }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment