| Path: | README.rdoc |
| Last Update: | Sun May 01 07:51:31 -0700 2011 |
rails plugin install git@github.com:jeroeningen/acts_as_price.git
Create a column in the table of your database which you want to acts as a price.
NOTE THAT THE COLUMN MUST BE OF THE TYPE INTEGER.
In your model add the following:
column_name is the name of your database column e.g. price or price_per_liter.
validates is optional and add validation to the column
comma_seperated is optional and return the price comma seperated instead of dot seperated
currency is optional and adds a prefix for the currency to the price.
This plugin creates the following getters and setters:
class Car < ActiveRecord::Base acts_as_price :price, :comma_seperated => true, :currency => "EUR" end
car = Car.new :price => 12999
car.price -> EUR. 12999,00
car.price_in_cents -> 1299900
class Fueltype < ActiveRecord::Base acts_as_price :price_per_liter, :validates => true end
fuel = Fueltype.new :price_per_liter => 1.12
fuel.price -> 1.12
fuel.price_in_cents -> 112
fuel.price_per_liter -> 1.12
fuel.price_per_liter_in_cents -> 1.12
Acts As Price comes with a helper method to automatically test the plugin using Rspec.
To use this method please add the following to your spec_helper.rb file:
Now you may add the following code to your spec-files for your models:
context "given an valid model" do
it "should acts as price" do
test_acts_as_price_methods <column_name>, <fixture or stub>
end
end
To test the plugin use the command ‘rspec spec/**’ inside the dir ’~/vendor/plugins/acts_as_price‘
The command ‘rake test’ is not running properly at the moment.
This plugin comes with Rspec tests. However this plugin assumes that you have a database configuration, it actually don‘t use the database for the Rspec tests.
For feedback and bug reports contact: jeroeningen@gmail.com