Skip to content

Commit

Permalink
Testing against Rails 4.1/4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tute committed Sep 7, 2014
1 parent e3c0d43 commit 1849e8b
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 118 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ env:
- RAILS_VERSION=3.2
- RAILS_VERSION=4.0
- RAILS_VERSION=4.0-protected-attributes
- RAILS_VERSION=4.1
- ORM=active_record
allow_failures:
- RAILS_VERSION=4.2
- ORM=mongoid
services:
- mongodb
10 changes: 6 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ source 'https://rubygems.org'

gemspec

version = ENV['RAILS_VERSION'] || '3.2'
version = ENV['RAILS_VERSION'] || '4.1'
rails = case version
when 'master'
{ github: 'rails/rails' }
when '4.0-protected-attributes'
gem 'protected_attributes'
"~> 4.0.0"
when /4\.0|4\.1/
"~> #{version}.0"
when '4.0'
"~> #{version}.0"
when /4\.2/
"~> #{version}.0.beta1"
when '3.2'
gem 'strong_parameters'
"~> #{version}.0"
Expand All @@ -22,7 +24,7 @@ case ENV['ORM']
when 'active_record'
gem 'activerecord'
when 'mongoid'
gem 'mongoid', '3.1.0'
gem 'mongoid', '~> 3.1.0'
end

group :development, :test do
Expand Down
11 changes: 4 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
# encoding: UTF-8
require 'rubygems'
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

require 'rake'

require 'rake/testtask'

desc 'Default: run tests for all ORMs.'
task default: :test

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
t.verbose = true
end

task :default => :test

begin
require 'rdoc/task'

Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Merit'
Expand Down
3 changes: 1 addition & 2 deletions merit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ Gem::Specification.new do |s|

s.add_dependency 'ambry', '~> 0.3.0'
s.add_development_dependency 'rails', '>= 3.2.0'
s.add_development_dependency 'jquery-rails', '~> 2.1'
s.add_development_dependency 'capybara'
s.add_development_dependency 'simplecov'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'minitest-rails'
s.add_development_dependency 'mocha', '0.14'
s.add_development_dependency 'mocha', '1.1.0'
end
8 changes: 8 additions & 0 deletions test/dummy/db/migrate/20140906225844_create_players.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreatePlayers < ActiveRecord::Migration
def change
create_table :players do |t|
t.integer :sash_id
t.integer :level, default: 0
end
end
end
66 changes: 36 additions & 30 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,85 @@
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(:version => 20140211144001) do
ActiveRecord::Schema.define(version: 20140906225844) do

create_table "addresses", :force => true do |t|
create_table "addresses", force: true do |t|
t.integer "user_id"
end

create_table "badges_sashes", :force => true do |t|
create_table "badges_sashes", force: true do |t|
t.integer "badge_id"
t.integer "sash_id"
t.boolean "notified_user", :default => false
t.boolean "notified_user", default: false
t.datetime "created_at"
end

add_index "badges_sashes", ["badge_id", "sash_id"], :name => "index_badges_sashes_on_badge_id_and_sash_id"
add_index "badges_sashes", ["badge_id"], :name => "index_badges_sashes_on_badge_id"
add_index "badges_sashes", ["sash_id"], :name => "index_badges_sashes_on_sash_id"
add_index "badges_sashes", ["badge_id", "sash_id"], name: "index_badges_sashes_on_badge_id_and_sash_id"
add_index "badges_sashes", ["badge_id"], name: "index_badges_sashes_on_badge_id"
add_index "badges_sashes", ["sash_id"], name: "index_badges_sashes_on_sash_id"

create_table "comments", :force => true do |t|
create_table "comments", force: true do |t|
t.string "name"
t.text "comment"
t.integer "user_id"
t.integer "votes", :default => 0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "votes", default: 0
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "sash_id"
t.integer "level", :default => 0
t.integer "level", default: 0
end

create_table "merit_actions", :force => true do |t|
create_table "merit_actions", force: true do |t|
t.integer "user_id"
t.string "action_method"
t.integer "action_value"
t.boolean "had_errors", :default => false
t.boolean "had_errors", default: false
t.string "target_model"
t.integer "target_id"
t.boolean "processed", :default => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "processed", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "target_data"
end

create_table "merit_activity_logs", :force => true do |t|
create_table "merit_activity_logs", force: true do |t|
t.integer "action_id"
t.string "related_change_type"
t.integer "related_change_id"
t.string "description"
t.datetime "created_at"
end

create_table "merit_score_points", :force => true do |t|
create_table "merit_score_points", force: true do |t|
t.integer "score_id"
t.integer "num_points", :default => 0
t.integer "num_points", default: 0
t.string "log"
t.datetime "created_at"
end

create_table "merit_scores", :force => true do |t|
create_table "merit_scores", force: true do |t|
t.integer "sash_id"
t.string "category", :default => "default"
t.string "category", default: "default"
end

create_table "sashes", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
create_table "players", force: true do |t|
t.integer "sash_id"
t.integer "level", default: 0
end

create_table "sashes", force: true do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "users", :force => true do |t|
create_table "users", force: true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "sash_id"
t.integer "level", :default => 0
t.integer "level", default: 0
end

end
62 changes: 30 additions & 32 deletions test/integration/navigation_test.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'test_helper'

class NavigationTest < ActiveSupport::IntegrationCase
def tear_down
class NavigationTest < ActionDispatch::IntegrationTest
def teardown
DummyObserver.unstub(:update)
end

test 'user sign up should grant badge to itself' do
DummyObserver.any_instance.expects(:update).times(1).with do |hash|
hash[:description] == 'granted just-registered badge' &&
hash[:sash_id] == user('Jack').sash_id &&
hash[:granted_at].to_date == Date.today
end
hash[:description] == 'granted just-registered badge' &&
hash[:sash_id] == user('Jack').sash_id &&
hash[:granted_at].to_date == Time.now.utc.to_date
end

visit '/users/new'
fill_in 'Name', with: 'Jack'
Expand Down Expand Up @@ -48,18 +48,16 @@ def tear_down

test 'users#index should grant badge multiple times' do
DummyObserver.any_instance.expects(:update).times(1).with do |hash|
hash[:description] == 'granted visited_admin badge' &&
hash[:sash_id] == user.sash_id
end
hash[:description] == 'granted visited_admin badge' &&
hash[:sash_id] == user.sash_id
end
DummyObserver.any_instance.expects(:update).times(5).with do |hash|
hash[:description] == 'granted gossip badge' &&
hash[:sash_id] == user.sash_id
end
8.times do |merit_action_id|
DummyObserver.any_instance.expects(:update).times(1).with do |hash|
hash[:description] == 'granted wildcard_badge badge' &&
hash[:sash_id] == user.sash_id
end
hash[:description] == 'granted gossip badge' &&
hash[:sash_id] == user.sash_id
end
DummyObserver.any_instance.expects(:update).times(8).with do |hash|
hash[:description] == 'granted wildcard_badge badge' &&
hash[:sash_id] == user.sash_id
end

# Multiple rule
Expand Down Expand Up @@ -262,21 +260,21 @@ def tear_down

test 'assigning points to a group of records' do
DummyObserver.any_instance.expects(:update).times(2).with do |hash|
hash[:description] == 'granted 1 points' &&
hash[:sash_id] == user('commenter').sash_id
end
hash[:description] == 'granted 1 points' &&
hash[:sash_id] == user('commenter').sash_id
end
DummyObserver.any_instance.expects(:update).times(1).with do |hash|
hash[:description] == 'granted 2 points' &&
hash[:sash_id] == user('commenter').comments.first.sash_id
end
hash[:description] == 'granted 2 points' &&
hash[:sash_id] == user('commenter').comments.first.sash_id
end
DummyObserver.any_instance.expects(:update).times(1).with do |hash|
hash[:description] == 'granted 2 points' &&
hash[:sash_id] == user('commenter').comments.last.sash_id
end
hash[:description] == 'granted 2 points' &&
hash[:sash_id] == user('commenter').comments.last.sash_id
end
DummyObserver.any_instance.expects(:update).times(1).with do |hash|
hash[:description] == 'granted 5 points' &&
hash[:sash_id] == user('commenter').sash_id
end
hash[:description] == 'granted 5 points' &&
hash[:sash_id] == user('commenter').sash_id
end

comment_1 = user('commenter').comments.create(name: 'a', comment: 'a')
comment_2 = user('commenter').comments.create(name: 'b', comment: 'b')
Expand All @@ -296,9 +294,9 @@ def tear_down

test 'api/comments#show should grant 1 point to user' do
DummyObserver.any_instance.expects(:update).times(1).with do |hash|
hash[:description] == 'granted 1 points' &&
hash[:sash_id] == user.sash_id
end
hash[:description] == 'granted 1 points' &&
hash[:sash_id] == user.sash_id
end

assert_equal 0, user.points
comment = user.comments.create!(name: 'test-comment', comment: 'comment body')
Expand Down
4 changes: 0 additions & 4 deletions test/orm_models/active_record.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
require 'test_helper'

class User < ActiveRecord::Base
has_merit
end

class Fruit < ActiveRecord::Base
end

Expand Down
5 changes: 0 additions & 5 deletions test/orm_models/mongoid.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
require 'test_helper'

class User
include Mongoid::Document
has_merit
end

class Fruit
include Mongoid::Document
end
Expand Down
2 changes: 1 addition & 1 deletion test/support/integration_case.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Define a bare test case to use with Capybara
class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
include Capybara::DSL
include Rails.application.routes.url_helpers
end
21 changes: 8 additions & 13 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
ENV['RAILS_ENV'] = 'test'
RUBYOPT="-w $RUBYOPT"

require 'coveralls'
Coveralls.wear!('rails')

if ENV["COVERAGE"]
require 'coveralls'
require 'simplecov'

Coveralls.wear!('rails')

SimpleCov.adapters.define 'rubygem' do
# Add app to Merit group
# https://github.com/colszowka/simplecov/pull/104
Expand All @@ -17,10 +18,10 @@
SimpleCov.start 'rubygem'
end


require File.expand_path('../dummy/config/environment.rb', __FILE__)
require 'rails/test_help'
require 'minitest/rails'
require "orm/#{Merit.orm}"

Rails.backtrace_cleaner.remove_silencers!

Expand All @@ -29,17 +30,11 @@
Capybara.default_driver = :rack_test
Capybara.default_selector = :css

# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

Merit.orm = :active_record if Merit.orm.nil?

def active_record_orm?
Merit.orm == :active_record
end

def mongoid_orm?
Merit.orm == :mongoid
end

require "orm/#{Merit.orm}"

# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
6 changes: 3 additions & 3 deletions test/unit/base_target_finder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
it 'should fall back to the action#target_model' do
rule = Merit::Rule.new
rule.to = :itself
action = Merit::Action.new(target_model: 'users', target_id: 3)
user = Comment.new(id: 3)
action = Merit::Action.new(target_model: 'players', target_id: 3)
user = Player.new(id: 3)

User.stubs(:find_by_id).with(3).returns(user)
Player.stubs(:find_by_id).with(3).returns(user)

finder = Merit::BaseTargetFinder.new(rule, action)
finder.find.must_be :==, user
Expand Down
Loading

0 comments on commit 1849e8b

Please sign in to comment.