Giter Club home page Giter Club logo

memory_test_fix's Introduction

MemoryTestFix

A simple fix to run your Rails tests with sqlite. From the example by Chris Roos.

Status

Dependency Status Build Status Code Climate

Usage

Add the gem to your bundle by adding

gem 'memory_test_fix'

to your Gemfile.

In your database.yml, use:

test:
  adapter: sqlite3
  database: ":memory:"

It runs much faster!

You can also adjust the verbosity of the output:

test:
  adapter: sqlite3
  database: ":memory:"
  verbosity: silent

To use rails migrations instead of loading db/schema.rb

test:
  adapter: sqlite3
  database: ":memory:"
  migrate: true

You can also use this with other (testing) environments, not just 'test'.

Rails Versions

In general, Bundler should pick a compatible version for you if you don't specify one in your Gemfile.

That said, the latest version of this gem is compatible with Rails 5.0, 5.1 and upcoming 5.2. If you're still on Rails 4, you can use version 1.3.0. Unfortunately, the hard requirement of Ruby 2.2 or above for Rails 5 means memory_test_fix cannot support Rails 4 and 5 at the same time.

If you're using a version of Rails older than 4, your first priority should be upgrading Rails. If that's really not an option, you can use version 1.2.2 of this gem with Rails 3.2. If you're using Rails 3.1 or 3.0, use version 1.1.0. If you're using Rails 2.3, use version 0.2.2. If you're using an even older version of Rails, use version 0.1.3.

Authors

The original hack this gem is based on was created by Chris Roos.

The hack was adapted as a Rails plugin by Geoffrey Grosenbach.

The following people have contributed:

  • Kakutani Shintaro
  • Matijs van Zuijlen
  • Erik Hanson & Matt Scilipoti
  • Greg Weber
  • Stephan Zalewski

MemoryTestFix is maintained by Matijs van Zuijlen

memory_test_fix's People

Contributors

gregwebs avatar jonnii avatar mvz avatar stepahn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

memory_test_fix's Issues

Breaks with Rails 4.2.1 and Spring

To test

rails new test

add the gem, bundle install and edit config/database.yml appropriately.

rails g scaffold test
rake db:migrate
rake test

the error is:

ActiveRecord::PendingMigrationError:
Migrations are pending. To resolve this issue, run:
bin/rake db:migrate RAILS_ENV=test

note: running bin/rake db:migrate RAILS_ENV=test does not resolve the issue

Dependency collision with Rails 5 / activerecord

Hey, thanks for the great gem. When trying to upgrade to Rails 5, it currently can't be used, because the activerecord version is incompatible:

$ bundle update
Fetching gem metadata from https://rubygems.org/...........
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies......
Bundler could not find compatible versions for gem "activerecord":
  In Gemfile:
    memory_test_fix (~> 1.3.0) was resolved to 1.3.0, which depends on
      activerecord (< 4.99.0, >= 4.0.0)

    rails (~> 5.0.0) was resolved to 5.0.0, which depends on
      activerecord (= 5.0.0)

schema.rb vs. migrations

Hi,

The docs mention that you can specify migrate: true to use migrations instead of the pre-generated schema.rb.

I'm a bit new to Rails (again). What's the trade-off here? How would I know which one to choose?

Use in production?

Is there any way to use this in production or in development mode? I would like to use this as a lightweight memory cache (while also not having to rework a ton of gems that expect ActiveRecord)

The error:

rails s
=> Booting WEBrick
=> Rails 4.2.4 application starting in development on ******
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Creating sqlite :memory: database
== 20151120220154 CreateEmails: migrating =====================================
-- create_table(:emails)
   -> 0.0013s
== 20151120220154 CreateEmails: migrated (0.0014s) ============================

== 20151121201244 CreateAttachments: migrating ================================
-- create_table(:attachments)
   -> 0.0012s
== 20151121201244 CreateAttachments: migrated (0.0012s) =======================

== 20151124191325 AddDocumentToAttachment: migrating ==========================
-- add_column(:attachments, :identifier, :string)
   -> 0.0004s
-- add_column(:attachments, :original_filename, :string)
   -> 0.0004s
-- add_column(:attachments, :content_type, :string)
   -> 0.0003s
-- add_column(:attachments, :size, :integer)
   -> 0.0003s
-- add_column(:attachments, :data, :binary)
   -> 0.0004s
== 20151124191325 AddDocumentToAttachment: migrated (0.0022s) =================

[2015-11-24 16:24:03] INFO  WEBrick 1.3.1
[2015-11-24 16:24:03] INFO  ruby 2.2.3 (2015-08-18) [x86_64-linux]
[2015-11-24 16:24:03] INFO  WEBrick::HTTPServer#start: pid=7568 port=3000

Started GET "/emails/new" for 10.4.2.117 at 2015-11-24 16:25:14 -0500

ActiveRecord::PendingMigrationError (

Migrations are pending. To resolve this issue, run:

        bin/rake db:migrate RAILS_ENV=development

):
...

I am currently using:

    rails (4.2.4)
    spring (1.4.4)
    memory_test_fix (1.3.0)

database.yml:

default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000
  database: ":memory:"
  migrate: true

development:
  <<: *default
  #database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  #database: db/test.sqlite3

production:
  <<: *default
  #database: db/production.sqlite3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.