Permalink
Browse files

Added tests and a few bugfixes. Version bump

  • Loading branch information...
1 parent f219359 commit 04f54462cf7a7047919b89ccd2ed8d6ca103102d @willcosgrove committed May 4, 2012
Showing with 1,235 additions and 3 deletions.
  1. +2 −0 .rspec
  2. +1 −0 Gemfile
  3. +8 −2 lib/priceable.rb
  4. +1 −1 lib/priceable/version.rb
  5. +3 −0 priceable.gemspec
  6. +27 −0 spec/priceable_spec.rb
  7. +14 −0 spec/spec_helper.rb
  8. +15 −0 test/dummy/.gitignore
  9. +39 −0 test/dummy/Gemfile
  10. +261 −0 test/dummy/README.rdoc
  11. +7 −0 test/dummy/Rakefile
  12. BIN test/dummy/app/assets/images/rails.png
  13. +15 −0 test/dummy/app/assets/javascripts/application.js
  14. +13 −0 test/dummy/app/assets/stylesheets/application.css
  15. +3 −0 test/dummy/app/controllers/application_controller.rb
  16. +2 −0 test/dummy/app/helpers/application_helper.rb
  17. 0 test/dummy/app/mailers/.gitkeep
  18. 0 test/dummy/app/models/.gitkeep
  19. +5 −0 test/dummy/app/models/llama.rb
  20. +3 −0 test/dummy/app/models/pig.rb
  21. +14 −0 test/dummy/app/views/layouts/application.html.erb
  22. +4 −0 test/dummy/config.ru
  23. +59 −0 test/dummy/config/application.rb
  24. +6 −0 test/dummy/config/boot.rb
  25. +25 −0 test/dummy/config/database.yml
  26. +5 −0 test/dummy/config/environment.rb
  27. +37 −0 test/dummy/config/environments/development.rb
  28. +67 −0 test/dummy/config/environments/production.rb
  29. +37 −0 test/dummy/config/environments/test.rb
  30. +7 −0 test/dummy/config/initializers/backtrace_silencers.rb
  31. +15 −0 test/dummy/config/initializers/inflections.rb
  32. +5 −0 test/dummy/config/initializers/mime_types.rb
  33. +7 −0 test/dummy/config/initializers/secret_token.rb
  34. +8 −0 test/dummy/config/initializers/session_store.rb
  35. +14 −0 test/dummy/config/initializers/wrap_parameters.rb
  36. +5 −0 test/dummy/config/locales/en.yml
  37. +58 −0 test/dummy/config/routes.rb
  38. +10 −0 test/dummy/db/migrate/20120503232408_create_llamas.rb
  39. +10 −0 test/dummy/db/migrate/20120504005527_create_pigs.rb
  40. +30 −0 test/dummy/db/schema.rb
  41. +7 −0 test/dummy/db/seeds.rb
  42. 0 test/dummy/lib/assets/.gitkeep
  43. 0 test/dummy/lib/tasks/.gitkeep
  44. 0 test/dummy/log/.gitkeep
  45. +26 −0 test/dummy/public/404.html
  46. +26 −0 test/dummy/public/422.html
  47. +25 −0 test/dummy/public/500.html
  48. 0 test/dummy/public/favicon.ico
  49. +241 −0 test/dummy/public/index.html
  50. +5 −0 test/dummy/public/robots.txt
  51. +6 −0 test/dummy/script/rails
  52. 0 test/dummy/test/fixtures/.gitkeep
  53. +9 −0 test/dummy/test/fixtures/llamas.yml
  54. +9 −0 test/dummy/test/fixtures/pigs.yml
  55. 0 test/dummy/test/functional/.gitkeep
  56. 0 test/dummy/test/integration/.gitkeep
  57. +12 −0 test/dummy/test/performance/browsing_test.rb
  58. +13 −0 test/dummy/test/test_helper.rb
  59. 0 test/dummy/test/unit/.gitkeep
  60. +7 −0 test/dummy/test/unit/llama_test.rb
  61. +7 −0 test/dummy/test/unit/pig_test.rb
  62. 0 test/dummy/vendor/assets/javascripts/.gitkeep
  63. 0 test/dummy/vendor/assets/stylesheets/.gitkeep
  64. 0 test/dummy/vendor/plugins/.gitkeep
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
@@ -1,4 +1,5 @@
source 'https://rubygems.org'
# Specify your gem's dependencies in priceable.gemspec
+gem 'sqlite3'
gemspec
View
@@ -1,15 +1,21 @@
require "priceable/version"
module Priceable
+ SUFFIXES = ["_in_cents", "_in_pennies"]
def priceable(*price_fields)
price_fields.each do |price_field|
+ suffix = SUFFIXES.detect { |suffix| self.attribute_method? "#{price_field}#{suffix}".to_sym }
+ raise ArgumentError, "Unable to find valid database field for `#{price_field}'" unless suffix
define_method price_field do
- send("#{price_field}_in_cents".to_sym) / 100.0
+ send("#{price_field}#{suffix}".to_sym) / 100.0
end
define_method "#{price_field}=".to_sym do |new_price|
- send("#{price_field}_in_cents=".to_sym, new_price * 100)
+ send("#{price_field}#{suffix}=".to_sym, new_price * 100)
end
end
+ if self._accessible_attributes?
+ attr_accessible *price_fields
+ end
end
end
View
@@ -1,3 +1,3 @@
module Priceable
- VERSION = "0.0.1"
+ VERSION = "0.0.2"
end
View
@@ -14,4 +14,7 @@ Gem::Specification.new do |gem|
gem.name = "priceable"
gem.require_paths = ["lib"]
gem.version = Priceable::VERSION
+
+ gem.add_development_dependency('rails')
+ gem.add_development_dependency('rspec')
end
View
@@ -0,0 +1,27 @@
+require "spec_helper"
+
+describe Priceable do
+ let(:llama) { Llama.new }
+
+ it "should create a getter method" do
+ llama.price_in_cents = 10000
+ llama.price.should == 100
+ end
+
+ it "should create a setter method" do
+ llama.price = 200
+ llama.price_in_cents.should == 20000
+ end
+
+ it "should set it as attr_accessible" do
+ Llama.accessible_attributes.to_a.should include("price")
+ end
+
+ it "should not set it as attr_accessible if there are no accessible attributes already set" do
+ Pig.accessible_attributes.to_a.should_not include("price")
+ end
+
+ it "should raise an ArgumentError if there is no database field set" do
+ lambda { Pig.send(:priceable, :cost) }.should raise_error(ArgumentError)
+ end
+end
View
@@ -0,0 +1,14 @@
+# This file was generated by the `rspec --init` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# Require this file using `require "spec_helper.rb"` to ensure that it is only
+# loaded once.
+#
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+ENV['RAILS_ENV'] = 'test'
+require_relative '../test/dummy/config/environment'
+
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+end
View
@@ -0,0 +1,15 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
View
@@ -0,0 +1,39 @@
+source 'https://rubygems.org'
+
+gem 'rails', '3.2.3'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3'
+
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', '~> 3.2.3'
+ gem 'coffee-rails', '~> 3.2.1'
+
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
+ # gem 'therubyracer', :platform => :ruby
+
+ gem 'uglifier', '>= 1.0.3'
+end
+
+gem 'jquery-rails'
+gem 'priceable', path: '../../'
+
+# To use ActiveModel has_secure_password
+# gem 'bcrypt-ruby', '~> 3.0.0'
+
+# To use Jbuilder templates for JSON
+# gem 'jbuilder'
+
+# Use unicorn as the app server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
Oops, something went wrong.

0 comments on commit 04f5446

Please sign in to comment.