Permalink
Browse files

Mongoid code polishings.

  • Loading branch information...
1 parent e950755 commit 7fbe0f939e35a7b55dd6bf890b1a7d52de3bb420 @tute tute committed Jun 5, 2012
View
6 .gitignore
@@ -4,7 +4,5 @@
log/*.log
pkg/
test/dummy/db/*.sqlite3
-test/dummy/log/*.log
-test/dummy/tmp/
-test/dummy-mongoid/log/*.log
-test/dummy-mongoid/tmp/
+test/dummy*/log/*.log
+test/dummy*/tmp/
View
5 .travis.yml
@@ -1,8 +1,13 @@
language: ruby
+
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
+env:
+ - ORM=activerecord
+ - ORM=mongoid
+
matrix:
allow_failures:
- rvm: 1.8.7
View
8 Gemfile
@@ -1,6 +1,8 @@
source "http://rubygems.org"
-gem "bson_ext"
-gem "mongoid","2.4.8"
-gem 'mongoid_auto_increment_id', "0.4.0"
+# TODO: Why do we need them here if they are in .gemspec?
+gem 'bson_ext'
+gem 'mongoid', '2.4.8'
+gem 'mongoid_auto_increment_id', '0.4.0'
+
gemspec
View
4 Gemfile.lock
@@ -1,8 +1,8 @@
PATH
remote: .
specs:
- merit (0.7.0)
- ambry
+ merit (0.7.1)
+ ambry (~> 0.3.0)
GEM
remote: http://rubygems.org/
View
4 README.md
@@ -115,11 +115,13 @@ Check for rules on a rake task executed in background like:
# To-do list
+* Can infer params[:id] = instance_variable.id in create actions, for having
+ the object in the rule method parameter, so we don't need it in controllers.
* add an error handler for inexistent badges.
* rails g merit MODEL_NAME shouldn't create general migrations again.
* Abstract User (rule.rb#51 for instance) into a Merit option.
* Should namespace app/models into Merit module.
-* rescue ActiveRecord::... should depend on ORM used (MongoMapper?)
+* rescue ActiveRecord::... should depend on ORM used
* Why 1.8.7 tests are not passing?
* :value parameter (for star voting for example) should be configurable
(depends on params[:value] on the controller).
View
11 TESTING.txt
@@ -1,13 +1,16 @@
cd test/dummy
-rails g merit:install # Next n's for not overriding already defined rules
+rails g merit:install # n's for not overriding already defined badges & rules
+n
n
n
n
rails g merit user
rake db:migrate ; rake db:seed
+
# see it in the browser
rails server
+
# or run tests
-cd ../.. ; rake test
-# or run tests with Mongoid
-cd ../.. ; ORM=mongoid rake test
+cd ../..
+rake test
+ORM=mongoid rake test
View
6 lib/merit.rb
@@ -21,10 +21,10 @@ def self.setup
class Engine < Rails::Engine
initializer 'merit.controller' do |app|
- # Merit.orm now set
if Merit.orm == :active_record
- # This line to fix rails g merit:install raise "uninitialized constant ActiveRecord" with Mongoid projects.
- if Module.const_defined?("ActiveRecord")
+ # This line to fix rails g merit:install raise "uninitialized constant
+ # ActiveRecord" with Mongoid projects.
+ if Module.const_defined?('ActiveRecord')
require "merit/models/#{Merit.orm}/sash"
require "merit/models/#{Merit.orm}/badges_sash"
end
View
2 lib/merit/model_additions.rb
@@ -26,7 +26,7 @@ def badges
# Create sash if doesn't have
def create_sash_if_none
if self.sash.blank?
- self.sash = Sash.create
+ self.sash = Sash.new
self.save(:validate => false)
end
end
View
3 lib/merit/rules_rank.rb
@@ -28,7 +28,6 @@ def check_rank_rules
level_and_rules = level_and_rules.sort
level_and_rules.each do |level, rule|
begin
- items = []
if Merit.orm == :mongoid
items = scoped_model.where(:"#{rule.level_name}".lt => level)
else
@@ -51,4 +50,4 @@ def defined_rules
@defined_rules ||= {}
end
end
-end
+end
View
6 merit.gemspec
@@ -7,10 +7,14 @@ Gem::Specification.new do |s|
s.version = "0.7.1"
s.authors = ["Tute Costa"]
s.email = 'tutecosta@gmail.com'
- s.add_dependency 'ambry'
+ s.add_dependency 'ambry', '~> 0.3.0'
s.add_development_dependency 'rails', '~> 3.2.3'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'haml'
s.add_development_dependency 'capybara'
s.add_development_dependency 'simplecov'
+ # Testing with Mongoid
+ s.add_development_dependency 'bson_ext'
+ s.add_development_dependency 'mongoid', '2.4.8'
+ s.add_development_dependency 'mongoid_auto_increment_id', '0.4.0'
end
View
1 test/dummy-mongoid/config/application.rb
@@ -12,7 +12,6 @@ class Application < Rails::Application
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
- # config.active_record.whitelist_attributes = true
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
View
2 test/dummy/config/initializers/merit.rb
@@ -3,7 +3,7 @@
# Check rules on each request or in background
# config.checks_on_each_request = true
- # Define ORM. Could be :active_record (default) and :mongo_mapper and :mongoid
+ # Define ORM. Could be :active_record (default), :mongo_mapper and :mongoid
# config.orm = :active_record
end
View
15 test/merit_unit_test.rb
@@ -14,13 +14,12 @@ class MeritUnitTest < ActiveSupport::TestCase
end
test "BadgeSash knows it's related badge" do
- if ENV["ORM"] == "mongoid"
- # SKIP
- else
- Badge.create(:id => 99, :name => 'test-badge')
- badge_sash = BadgesSash.new
- badge_sash.badge_id = 99
- assert_equal Badge.find(99), badge_sash.badge
- end
+ # No BadgeSash model for Mongoid
+ return if ENV["ORM"] == "mongoid"
+
+ Badge.create(:id => 99, :name => 'test-badge')
+ badge_sash = BadgesSash.new
+ badge_sash.badge_id = 99
+ assert_equal Badge.find(99), badge_sash.badge
end
end

0 comments on commit 7fbe0f9

Please sign in to comment.