Sha256: 0897d4348a9e596adb46505ae28b8c0752dc5a781392d43898bdf41e3f26927a
Contents?: true
Size: 1.38 KB
Versions: 5
Compression:
Stored size: 1.38 KB
Contents
require 'spec_helper' require 'active_record' require 'nulldb' describe "Stubbing ActiveRecord::Base subclasses" do ActiveRecord::Schema.verbose = false ActiveRecord::Base.establish_connection :adapter => :nulldb ActiveRecord::Schema.define do create_table :blog_posts do |t| t.string :name t.string :author end end class BlogPost < ActiveRecord::Base def author(x) "#{x} #{self[:author]}!" end end include Bogus::MockingDSL before do Bogus.configure do |c| c.fake_ar_attributes = true end end it "makes it possible to stub active record fields" do post = fake(:blog_post, name: "hello") post.name.should == "hello" end it "works only when enabled in configuration" do Bogus.configure do |c| c.fake_ar_attributes = false end expect { fake(:blog_post, name: "hello") }.to raise_error(NameError) end it "does not overwrite existing method signatures" do post = fake(:blog_post) post.author("hello") post.should have_received.author("hello") end class ExampleForActiveRecordAttributes def foo(x) end end it "does not interfere with non-ar classes" do fake = fake(:example_for_active_record_attributes) fake.foo(1) fake.should have_received.foo(1) end after do Bogus.configure do |c| c.fake_ar_attributes = false end end end
Version data entries
5 entries across 5 versions & 1 rubygems