Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix broken migrations caused by #290 #323

Merged
merged 2 commits into from

8 participants

@james2m

Hi Ben,

I've fixed #318 and #322 which were caused by #290 raising an exception on !db_setup? which meant migrations were never run. I've partially restored your original code to check whether the table exists.

It would be good to get this in as it's hindering people setting up new projects with Authlogic.

J.

james2m added some commits
@marcomorain

Thanks for fixing this James. It would be great to get this merged as soon as possible, we had to jump though some hoops to work around it.

@ctilley83

Cloning the fixed branch does not work. Why can't you merge the fix into master. It seems like it's taking an act of God to get this fixed.

@james2m
@ctilley83
@james2m

Can you tell me what the typo is and I'll fix it.

@maletor

+5

@timols

+1

@binarylogic binarylogic merged commit beaabc5 into binarylogic:master
@rstacruz

This fix has a small caveat. If you have User.create in your seeder (db/seeds.rb), this won't be doable anymore:

$ rake db:drop
$ rake db:setup

It gets you this error:

undefined method 'password=' for #<User:....>

This is because acts_as_authentic has return unless table_exists? which stops it from creating the password= method.

@rstacruz

...actually, forget that: that bug has existed since 2 years ago.#88

@james2m

@rstacruz That explains something I've never got round to investigating. It's only a problem if you run your seeds in the same session as your migrations right? e.g.

$ rake db:migrate db:seed
@rstacruz

@james2m Yes, which Rails does by default with:

$ rake db:setup

...which is simply an alias for db:create db:schema:load db:seed.

@james2m james2m deleted the james2m:fix-migrations branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 11, 2012
  1. @james2m

    Ignored .rvmrc files.

    james2m authored
  2. @james2m

    Fixes #318 and fixes #322 broken migrations caused by #290.

    james2m authored
    Signed-off-by: James McCarthy <james2mccarthy@gmail.com>
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -7,3 +7,4 @@ coverage/*
doc/*
benchmarks/*
.specification
+.rvmrc
View
5 lib/authlogic/acts_as_authentic/base.rb
@@ -28,7 +28,10 @@ module Config
# See the various sub modules for the configuration they provide.
def acts_as_authentic(unsupported_options = nil, &block)
# Stop all configuration if the DB is not set up
- raise StandardError.new("You must establish a database connection before using acts_as_authentic") if !db_setup?
+ return unless table_exists?
+
+ # Raise an error if you've loaded the model without establishing a valid database connection.
+ raise StandardError.new("You must establish a database connection before using acts_as_authentic") unless connection.present?
raise ArgumentError.new("You are using the old v1.X.X configuration method for Authlogic. Instead of " +
"passing a hash of configuration options to acts_as_authentic, pass a block: acts_as_authentic { |c| c.my_option = my_value }") if !unsupported_options.nil?
View
7 test/acts_as_authentic_test/base_test.rb
@@ -14,5 +14,12 @@ def test_acts_as_authentic_with_old_config
User.acts_as_authentic({})
end
end
+
+ def test_acts_as_authentic_with_no_table
+ klass = Class.new(ActiveRecord::Base)
+ assert_nothing_raised do
+ klass.acts_as_authentic
+ end
+ end
end
end
Something went wrong with that request. Please try again.