Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing class attribute resetting, which was failing on AR 3.1.

  • Loading branch information...
commit 012502f1331f8180c540eb5c5053e8a494a525d7 1 parent cfecf34
@flavorjones flavorjones authored
Showing with 25 additions and 9 deletions.
  1. +8 −1 lib/acts_as_fu/base.rb
  2. +17 −8 spec/acts_as_fu_spec.rb
View
9 lib/acts_as_fu/base.rb
@@ -1,4 +1,5 @@
-%w(rubygems active_record logger).each { |lib| require lib }
+require 'active_record'
+require 'logger'
RAILS_ROOT = File.join(File.dirname(__FILE__), '..') unless defined?(RAILS_ROOT)
RAILS_ENV = 'test' unless defined?(RAILS_ENV)
@@ -24,6 +25,12 @@ def build_model(name, options={}, &block)
super_class = options[:superclass] || ActsAsFu::Connection
contained = options[:contained] || Object
+ begin
+ old_klass = contained.const_get(klass_name)
+ old_klass.reset_column_information if old_klass.respond_to?(:reset_column_information)
+ rescue
+ end
+
contained.send(:remove_const, klass_name) rescue nil
klass = Class.new(super_class)
contained.const_set(klass_name, klass)
View
25 spec/acts_as_fu_spec.rb
@@ -71,27 +71,36 @@ def self.awesome?; true end
end
describe "rebuilding the class" do
- before(:each) do
+ it "clears the table" do
create_models
5.times { Foo.create!(:name => "The WHIZ", :age => 100) }
- end
-
- it "clears the table" do
Foo.count.should == 5
create_models
Foo.count.should == 0
end
it "resets the class" do
+ create_models
class << Foo; attr_reader :bar end
proc { Foo.bar }.should_not raise_error
create_models
-
- proc {
- Foo.bar
- }.should raise_error(NoMethodError)
+ proc { Foo.bar }.should raise_error(NoMethodError)
+ end
+
+ it "resets the attributes" do
+ build_model :fakers do
+ string :bar
+ end
+ proc { Faker.new :bar => "bar" }.should_not raise_error
+ proc { Faker.new :foo => "foo" }.should raise_error
+
+ build_model :fakers do
+ string :foo
+ end
+ proc { Faker.new :foo => "foo" }.should_not raise_error
+ proc { Faker.new :bar => "bar" }.should raise_error
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.