Discussion:
Rails3 + SQLA + RSpec
springbok
2010-09-10 08:56:06 UTC
Permalink
Hi Eric,

I'm trying to install my test framework including rspec, I get the
following error when running "rake spec":

Task not supported by 'sqlanywhere'

When I trace the rake task it fails here:

/home/etienne/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/
active_record/railties/databases.rake:453:in `block (3 levels) in <top
(required)>'

When I check the rake source I find that it fails in database.rake as
it does not support SQLA, i.e. :

# desc "Empty the test database"
task :purge => :environment do
abcs = ActiveRecord::Base.configurations
case abcs["test"]["adapter"]
when /mysql/
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.recreate_database(abcs["test"]
["database"], abcs["test"])
when "postgresql"
ActiveRecord::Base.clear_active_connections!
drop_database(abcs['test'])
create_database(abcs['test'])
when "sqlite","sqlite3"
dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
File.delete(dbfile) if File.exist?(dbfile)
when "sqlserver"
dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]
["database"]}.DP1".gsub(/\\/,'-')
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]
["database"]} -i db\\#{dropfkscript}`
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]
["database"]} -i db\\#{Rails.env}_structure.sql`
when "oci", "oracle"
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.structure_drop.split(";\n
\n").each do |ddl|
ActiveRecord::Base.connection.execute(ddl)
end
when "firebird"
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.recreate_database!
else
raise "Task not supported by '#{abcs["test"]["adapter"]}'"
end
end

There are a number of other tasks that execute DB specific commands
that do not currently support SQLA, for example:

desc "Dump the database structure to an SQL file"
task :dump => :environment do

# desc "Recreate the test databases from the development
structure"
task :clone_structure => [ "db:structure:dump", "db:test:purge" ]
do

plus others.

What would be the best approach for me to fix these problems do you
think? I could check each task and try and figure out the equivalent
SQLA utils/commands, but I'm not a 100% sure what the cleanest way
would be for me to add this to the current rake task??

Was this an issue in Rails2.x? I never actually used a test framework
with SQLA in Rails2.x so I don't know if that was a problem or not,

Any help appreciated as usual,

Etienne.
--
You received this message because you are subscribed to the Google Groups "SQL Anywhere Web Development" group.
To post to this group, send email to sql-anywhere-web-***@googlegroups.com.
To unsubscribe from this group, send email to sql-anywhere-web-development+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sql-anywhere-web-development?hl=en.
Eric Farrar
2010-09-21 13:38:14 UTC
Permalink
Hello Etienne,

It looks like the test harness has changed somewhat between 2.x and
3.x.

We had this problem in 2.x as well. ActiveRecord seems to be a little
confused with its plugin architectures since it allows you to add
plugins by simply copying files, but it will not allow "unknown" tests
to be run. In version 2.x you had to add the word "sqlanywhere" into
the rakefile. The instructions for this were in the sqlanywhere-
activerecord-adapter documentation found at
http://sqlanywhere.rubyforge.org/activerecord-sqlanywhere-adapter/ .

I have a open ticket (along with a patch) dating back to March 2009 on
the Rails mainline to have sqlanywhere added as a testable adapter
(
https://rails.lighthouseapp.com/projects/8994/tickets/2386-adding-sql-anywhe
re-support-to-activerecord-tests
). The milestone for this was recently changed from 2.x to 3.x, so I
am hoping it will be accepted soon.

I will take a look over the new test framework and see if I can figure
out the cleanest way to get it hooked up.

- Eric
Post by springbok
Hi Eric,
I'm trying to install my test framework including rspec, I get the
Task not supported by 'sqlanywhere'
/home/etienne/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.0/lib/
active_record/railties/databases.rake:453:in `block (3 levels) in <top
(required)>'
When I check the rake source I find that it fails in database.rake as
   # desc "Empty the test database"
    task :purge => :environment do
      abcs = ActiveRecord::Base.configurations
      case abcs["test"]["adapter"]
      when /mysql/
        ActiveRecord::Base.establish_connection(:test)
        ActiveRecord::Base.connection.recreate_database(abcs["test"]
["database"], abcs["test"])
      when "postgresql"
        ActiveRecord::Base.clear_active_connections!
        drop_database(abcs['test'])
        create_database(abcs['test'])
      when "sqlite","sqlite3"
        dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
        File.delete(dbfile) if File.exist?(dbfile)
      when "sqlserver"
        dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]
["database"]}.DP1".gsub(/\\/,'-')
        `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]
["database"]} -i db\\#{dropfkscript}`
        `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]
["database"]} -i db\\#{Rails.env}_structure.sql`
      when "oci", "oracle"
        ActiveRecord::Base.establish_connection(:test)
        ActiveRecord::Base.connection.structure_drop.split(";\n
\n").each do |ddl|
          ActiveRecord::Base.connection.execute(ddl)
        end
      when "firebird"
        ActiveRecord::Base.establish_connection(:test)
        ActiveRecord::Base.connection.recreate_database!
      else
        raise "Task not supported by '#{abcs["test"]["adapter"]}'"
      end
    end
There are a number of other tasks that execute DB specific commands
   desc "Dump the database structure to an SQL file"
   task :dump => :environment do
    # desc "Recreate the test databases from the development
structure"
    task :clone_structure => [ "db:structure:dump", "db:test:purge" ]
do
plus others.
What would be the best approach for me to fix these problems do you
think? I could check each task and try and figure out the equivalent
SQLA utils/commands, but I'm not a 100% sure what the cleanest way
would be for me to add this to the current rake task??
Was this an issue in Rails2.x? I never actually used a test framework
with SQLA in Rails2.x so I don't know if that was a problem or not,
Any help appreciated as usual,
Etienne.
--
You received this message because you are subscribed to the Google Groups "SQL Anywhere Web Development" group.
To post to this group, send email to sql-anywhere-web-***@googlegroups.com.
To unsubscribe from this group, send email to sql-anywhere-web-development+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sql-anywhere-web-development?hl=en.
Loading...