18 April 2014

The Ruby Reflector

Topic

ActiveRecord

  Source Favicon
By Mike Gunderloy of A Fresh Cup 3 months ago.
Email

When should I not kill -9 a process? - And what to do instead.

CoffeeScript 1.7.0 - A new release with some breaking changes is out.

The two biggest bugs fixed in Rails 4.1 - Well, debatable, but some important ActiveRecord fixes are coming.

afreshcup.com Read
  Source Favicon
Email

Data will still need to be checked for presence before insertion. The ActiveRecord gem gives you this with the "find or create" methods to locate a record or create it if it can't be found. In addition, those methods will basically force you to manually define each attribute you want assigned, making Factory Girl unnecessary.

What's next?

If you found this useful, you might also enjoy:

FactoryGirl Callbacks

FactoryGirl Traits

Use FactoryGirl

robots.thoughtbot.com Read
  Source Favicon
Email

When a Rails app boots, the ActiveRecord classes reflect on the database to determine which attributes and associations to add to the models. The config.cache_classes setting is true in production mode and false in development mode.

During development, we can write and run a migration and see the change take effect without restarting the web server but in production we need to restart the server for the ActiveRecord classes to learn about the new information from the database. …

robots.thoughtbot.com Read
  Source Favicon
By Sarah of the evolving ultrasaurus 6 months ago.
Email

…make a Rails app skipping test-unit (-T), since I prefer RSpec, and omitting ActiveRecord (-O) since we'll be using MongoDB. rails new parakeet -T -O cd parakeet

Add the following to the Gemfile gem "mongoid", git: 'git://github.com/mongoid/mongoid.git' gem "omniauth-twitter" gem "figaro" # key configuration using ENV

Now some auto-code generation for quick setup: rails g mongoid:config # create config/mongoid.yml

rails generate …

ultrasaurus.com Read
  Source Favicon
By Paul Gross of Paul Gross's Blog 7 months ago.
Email

The code above makes sure that we scope ActiveRecord methods to a merchant, but it doesn't cover all cases. For example, it doesn't stop code like this:

Customer. find_by_sql ( [ "SELECT * FROM customers WHERE token = ?" , "Paul" ] )

We write a decent amount of custom SQL in our application for performance, and we wanted to make sure these cases were safe as well. Therefore, we have a similar hack called the scoped find hook that checks ActiveRecord objects …

pgrs.net Read
  Source Favicon
By Adam Keys of The Real Adam 7 months ago.
Email

This advice is going on a year old, but it's still some of the best around. If you've got ungainly ActiveRecord objects that are doing way more than abstracting your data model, you are missing classes in the design of your application. Chances are, one of the objects Bryan describes here is what you might want to extract.

therealadam.com Read
  Source Favicon
On Fingertips 8 months ago.
Email

On Ruby 1.8.7 inserting records through ActiveRecord was really slow. Especially in loops, repeatedly called setup methods, or factories. In Rails 4.0 with Ruby 2.0 this has gotten less of an issue.

Unnecessary round-tripping to the database server and models with lots of callbacks, uniqueness checks, and other slow code can still slow down your test suite. A lot of methods and validations on a model can be tested without saving it.

Avoid connecting to remote services

You don't …

fngtps.com Read
  Source Favicon
On Fingertips 8 months ago.
Email

We can understand why factories are slow by looking at why ActiveRecord fixtures are fast.

Fixtures are bulk loaded once. A transaction is created in the database when a test starts. After the test the database is rolled back to its initial state. This means the fixtures don't have to be reloaded for each test.

Most factory implementations start a test with an empty database and run through all the factories needed for a test each time it's run. After the test the database is reset …

fngtps.com Read
  Source Favicon
By pat of Freelancing Gods 9 months ago.
Email

…definitely feature if I ever do get that opportunity: more and more, I like to avoid including modules into ActiveRecord and other parts of Rails - and if you peruse the source you'll see I'm only adding the absolute minimum to ActiveRecord::Base, plus I've pulled out the logic around the tag names collection and resulting persistence into a separate, simple class .

I got a nice little buzz when I had Code Climate scan the source and give it …

freelancing-gods.com Read
  Source Favicon
By pat of Freelancing Gods 9 months ago.
Email

This means that your ActiveRecord instances take priority - so pane methods don't overwrite your own code. It also allows for method_missing metaprogramming in your models (and ActiveRecord itself) - but otherwise, you can get access to the useful metadata Sphinx can provide, without monkeypatching objects on the fly.

If you're writing your own panes, the only requirement is that the initializer must accept three arguments: the search context, the underlying search result object, …

freelancing-gods.com Read