Skip to content
Browse files

Simple tests added

  • Loading branch information...
1 parent 68bedb9 commit 78da7c5db3557473f0b49a4c76b1edfb22dfc403 @jeroeningen committed
View
5 README.rdoc
@@ -58,7 +58,10 @@ Now you may add the following code to your spec-files for your models:
end
=TESTING
-To test the plugin use the command 'rake test' or 'rspec spec/*_spec.rb' inside the dir '~/vendor/plugins/acts_as_price'
+To test the plugin use the command 'rspec spec/**' inside the dir '~/vendor/plugins/acts_as_price'
+
+=KNOWN BUGS
+The command 'rake test' is not running properly at the moment.
=NOTES
This plugin comes with Rspec tests.
View
20 Rakefile
@@ -4,16 +4,16 @@ require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
-desc 'Default: run unit tests.'
-task :default => :test
-
-desc 'Test the acts_as_price plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.libs << 'spec'
- t.pattern = 'spec/*_spec.rb'
- t.verbose = true
-end
+#desc 'Default: run unit tests.'
+#task :default => :test
+#
+#desc 'Test the acts_as_price plugin.'
+#Rake::TestTask.new(:test) do |t|
+# t.libs << 'lib'
+# t.libs << 'spec'
+# t.pattern = 'spec/**/*spec.rb'
+# t.verbose = true
+#end
desc 'Generate documentation for the acts_as_price plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
View
2 VERSION
@@ -1 +1 @@
-0.2.0
+0.1.2
View
4 acts_as_price.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{acts_as_price}
- s.version = "0.1.1"
+ s.version = "0.1.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jeroen van Ingen"]
- s.date = %q{2011-04-28}
+ s.date = %q{2011-04-29}
s.description = %q{A specified database column acts as a price and creates on the fly methods like 'price' and 'price_in_cents'. For more information visit: http://github.com/jeroeningen/acts_as_price}
s.email = %q{jeroeningen@gmail.com}
s.extra_rdoc_files = [
View
2 rdoc/created.rid
@@ -1 +1 @@
-Fri, 29 Apr 2011 16:03:45 -0700
+Sun, 01 May 2011 07:33:52 -0700
View
11 rdoc/files/README_rdoc.html
@@ -56,7 +56,7 @@
</tr>
<tr class="top-aligned-row">
<td><strong>Last Update:</strong></td>
- <td>Fri Apr 29 15:27:33 -0700 2011</td>
+ <td>Sun May 01 07:30:16 -0700 2011</td>
</tr>
</table>
</div>
@@ -178,9 +178,12 @@
</pre>
<h1>TESTING</h1>
<p>
-To test the plugin use the command &#8216;rake test&#8217; or &#8216;rspec
-spec/*_spec.rb&#8217; inside the dir
-&#8217;~/vendor/plugins/acts_as_price&#8216;
+To test the plugin use the command &#8216;rspec spec/**&#8217; inside the
+dir &#8217;~/vendor/plugins/acts_as_price&#8216;
+</p>
+<h1>KNOWN BUGS</h1>
+<p>
+The command &#8216;rake test&#8217; is not running properly at the moment.
</p>
<h1>NOTES</h1>
<p>
View
2 spec/car_spec.rb → spec/advanced_tests/car_spec.rb
@@ -1,4 +1,4 @@
-require "#{File.dirname(__FILE__)}/spec_helper"
+require File.expand_path("../../spec_helper", __FILE__)
describe Car do
before(:each) do
View
2 spec/fueltype_spec.rb → spec/advanced_tests/fueltype_spec.rb
@@ -1,4 +1,4 @@
-require "#{File.dirname(__FILE__)}/spec_helper"
+require File.expand_path("../../spec_helper", __FILE__)
describe Fueltype do
before(:each) do
View
76 spec/simple_tests/car_and_fueltype_spec.rb
@@ -0,0 +1,76 @@
+require File.expand_path("../../spec_helper", __FILE__)
+
+#Car return the price as a comma seperated value
+describe Car do
+ context "adding a price as comma seperated value" do
+ it "should return the price as comma-seperated value" do
+ car = stub_model(Car, :price => "23000,59")
+ car.price.should == "23000,59"
+ end
+ it "should return the pricce in cents" do
+ car = stub_model(Car, :price => "23000,59")
+ car.price_in_cents.should == 2300059
+ end
+ end
+
+ context "adding the price as a dot seperated value" do
+ it "should return the price as a comma seperated value" do
+ car = stub_model(Car, :price => "23000.59")
+ car.price.should == "23000,59"
+ car = stub_model(Car, :price => "23000.5")
+ car.price.should == "23000,50"
+ end
+ end
+
+ context "adding the price as an integer" do
+ it "should return the price as a comma-seperated value" do
+ car = stub_model(Car, :price => "23000")
+ car.price.should == "23000,00"
+ end
+ end
+end
+
+#Fueltype returns the price as a dot seperated value
+describe Fueltype do
+ context "adding the price as an comma sewperated value" do
+ it "should return the price as a dot seperated value" do
+ fueltype = stub_model(Fueltype, :price_per_liter => "1,59")
+ fueltype.price.should == "1.59"
+ fueltype.price_per_liter.should == "1.59"
+ end
+ it "should return the price in cents" do
+ fueltype = stub_model(Fueltype, :price_per_liter => "1,59")
+ fueltype.price_per_liter_in_cents.should == 159
+ fueltype.price_in_cents.should == 159
+ end
+ end
+
+ context "adding the price as a dot seperated value" do
+ it "should return the price as a dot seperated value" do
+ fueltype = stub_model(Fueltype, :price_per_liter => "1.59")
+ fueltype.price_per_liter.should == "1.59"
+ fueltype.price.should == "1.59"
+ fueltype = stub_model(Fueltype, :price_per_liter => "1,5")
+ fueltype.price_per_liter.should == "1.50"
+ fueltype.price.should == "1.50"
+ end
+ end
+
+ context "adding the price as an integer" do
+ it "should return the price as a dot seperated value" do
+ fueltype = stub_model(Fueltype, :price_per_liter => "1")
+ fueltype.price_per_liter.should == "1.00"
+ fueltype.price.should == "1.00"
+ end
+ end
+
+ context "adding a price that could give a floating point problem" do
+ it "should return the right prices" do
+ fueltype = stub_model(Fueltype, :price_per_liter => "2,05")
+ fueltype.price.should == "2.05"
+ fueltype.price_per_liter.should == "2.05"
+ fueltype.price_in_cents.should == 205
+ fueltype.price_per_liter_in_cents.should == 205
+ end
+ end
+end

0 comments on commit 78da7c5

Please sign in to comment.
Something went wrong with that request. Please try again.