Skip to content

Instantly share code, notes, and snippets.

@why-el
Last active August 29, 2015 14:09
Show Gist options
  • Save why-el/5cc87cdc9db4a7c3acbb to your computer and use it in GitHub Desktop.
Save why-el/5cc87cdc9db4a7c3acbb to your computer and use it in GitHub Desktop.
money-rails's `t.money` syntax working with Rails.4.2.beta4
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.2.0.beta4'
gem 'pg'
gem 'money-rails'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'rails'
require 'active_record'
require 'money-rails'
MoneyRails::Hooks.init
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'ar_test')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :products do |t|
t.money :price, currency: { present: false }
t.timestamps
end
end
class Product < ActiveRecord::Base
monetize :price
end
class FooApp < Rails::Application
config.root = File.dirname(__FILE__)
config.session_store :cookie_store, key: 'cookie_store_key'
config.secret_token = 'secret_token'
config.secret_key_base = 'secret_key_base'
config.logger = Logger.new($stdout)
Rails.logger = config.logger
end
require 'minitest/autorun'
class FooTest < ActiveSupport::TestCase
def test_created_money_columns_successsfully
assert p = Product.new({price: 100})
puts p.price
end
private
def app
Rails.application
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment