I found the answer to my question from here.
Here’s the way:
activerecord:
attributes:
user:
first_name: "Name first"
I found the answer to my question from here.
Here’s the way:
activerecord:
attributes:
user:
first_name: "Name first"
Monkeypatch ActiveRecord with this:
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
and your spec_helper with this:
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before :each do
if Capybara.current_driver == :rack_test
DatabaseCleaner.strategy = :transaction
else
DatabaseCleaner.strategy = :truncation
end
DatabaseCleaner.start
end
config.after do
DatabaseCleaner.clean
end
end
Full info available on Nicholas Rutherford’s blog. Thanks Nicholas!
If you want to only select a few columns on a query, here’s how you can do it:
YourModel.find(:all,:select => "column1,column2")
First thing you have to do is find out the DATABASE_URL of the app you’re interested in. Run heroku config –app your_app to get it. Then, in the other app, run this:
heroku config:add DATABASE_URL=whatever_the_result_of_the_first_command_was
Establish an ActiveRecord connection:
db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/mydb')
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => db.host,
:username => db.user,
:password => db.password,
:database => db.path[1..-1],
:encoding => 'utf8'
)
state_machine is a nifty gem. Try it!
If you want to develop with CoffeeScript outside of Rails, here’s one way you could do it:
watch("js/application.coffee") do |s|
puts "#{Time.now} => Compiling #{s}"
system("coffee -c #{s[0]}")
end
watcher your_watch_file.rb
Assuming 31 is the line at which your test starts, do this:
rspec some.spec:31
Treetop seems pretty nice, but information on it’s usage is kind of scattered all over internet
. Here are a few tips that I used to debug grammars:
tree = parser.parse(content,:root => "rule_name")
if tree
puts "succesful"
else
puts "unsuccesful at #{parser.index}"
puts parser.failure_reason
end
Hope this helps you as much as it helped me.