Sha256: 8ce34107d780201624583e2f833b4dd57e086c3467b30215de4365e5680bfee5
Contents?: true
Size: 1.81 KB
Versions: 2
Compression:
Stored size: 1.81 KB
Contents
require "codeclimate-test-reporter" CodeClimate::TestReporter.start require 'rspec' require 'pry' require 'passive_record' class Model include PassiveRecord attr_accessor :created_at after_create { @created_at = Time.now } end class SimpleModel < Struct.new(:foo) include PassiveRecord attr_reader :updated_at after_update { @updated_at = Time.now } end module Family class Dog < Model attr_reader :sound attr_accessor :breed belongs_to :child before_create { @breed = %w[pom pug].sample } after_create { @sound = 'bark' } end class Toy < Model belongs_to :child attr_reader :kind after_create {@kind = %w[ stuffed_animal blocks cards ].sample} end class Child < Model has_one :toy has_many :dogs belongs_to :parent attr_reader :name after_create :give_name def give_name; @name = "Alice" end end class Parent < Model has_many :children has_many :dogs, :through => :children has_many :toys, :through => :children end end include Family ### class Patient < Model has_many :appointments has_many :doctors, :through => :appointments end class Appointment < Model belongs_to :patient belongs_to :doctor end class Doctor < Model has_many :appointments has_many :patients, :through => :appointments end ### # # self-referential case # class Friendship < Model belongs_to :user belongs_to :friend, class_name: "User" end class User < Model has_many :friendships has_many :friends, :through => :friendships has_and_belongs_to_many :roles end class Role < Model has_and_belongs_to_many :users end ### class Post < Model has_many :comments has_many :commenters, :through => :comments, :class_name => "User" end class User < Model has_many :comments end class Comment < Model belongs_to :post belongs_to :user end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
passive_record-0.3.5 | spec/spec_helper.rb |
passive_record-0.3.4 | spec/spec_helper.rb |