Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby JavaScript
tree: 58de78785f

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
Gemfile
MIT-LICENSE
README.rdoc
Rakefile
init.rb
install.rb
uninstall.rb

README.rdoc

INSTALLATION

rails plugin install git@github.com:jeroeningen/acts_as_price.git

USAGE

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:

  • acts_as_price column_name, :validates = true

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

This plugin creates the following getters and setters:

  • 'price_in_cents' and '<column_name>_in_cents' #sets and returns the price in cents

  • 'price' and '<column_name>' #sets and returns the price

EXAMPLES

car = Car.new :price => 12999

car.price #12999.00

car.price_in_cents #1299900

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

RSPEC INTERGRATION

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:

  • config.include(ActsAsPriceHelper)

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

TESTING

To test the plugin use the command 'rake test' or 'rspec spec/*_spec.rb' inside the dir '~/vendor/plugins/acts_as_price'

KNOWN BUGS

The acts_as_price plugin does not accept comma-seperated prices at the moment.

NOTES

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.

FEEDBACK AND BUGS REPORTS

For feedback and bug reports contact: jeroeningen@gmail.com

Something went wrong with that request. Please try again.