This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Battle do | |
context "new" do | |
let!(:battle) { Battle.new } | |
let!(:events) { [:can_open?, :can_close_no_opponent?, :can_start?, :can_close_no_video?, :can_close_no_videos?, :can_close_no_votes?, :can_close_ex_equo?, :can_close_more_votes?, :can_close?] } | |
it "should have default :pending status" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Battle < ActiveRecord::Base | |
include Workflow | |
default_value_for :state, "pending" | |
after_save :update_users_states | |
workflow_column :state | |
workflow do | |
state :pending do # valid for 2 weeks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BattleObserver < ActiveRecord::Observer | |
def after_save(battle) | |
BattleComputation.new(battle).update_users_states | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Battlejam | |
class Application < Rails::Application | |
... | |
config.active_record.observers = :battle_observer | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ClassHelpers | |
def new_user | |
User.new | |
end | |
def new_valid_user | |
User.new(valid_user_params) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe User do | |
include ClassHelpers | |
context "new" do | |
it "should create user with role_id = 2 (registered) by default" do | |
new_valid_user.role_id.should == 2 | |
new_valid_user.registered?.should be_true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* sweet.js (sjs) markup, can be compiled on http://sweetjs.org/browser/editor.html */ | |
let Math.max = macro { | |
rule { ([$x ...]) } => { Math.max ($x ...) } | |
rule { ($x ...) } => { Math.max ($x ...) } | |
} | |
// 1. Regular | |
Math.max(1,2) // => Math.max(1,2) | |
Math.max(3,4,5) // => Math.max(3,4,5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CoreRepository { | |
static inject () { | |
return []; | |
} | |
static instance () { | |
var deps = this.inject(); | |
return new this(...deps); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.service('Wallet', function () { | |
function Wallet () { | |
this.total = 0; | |
} | |
Wallet.prototype.add = function (amount) { | |
this.total += Number(amount) || 0; | |
return this.total; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AOP { | |
static extend(target) { | |
Object.assign(target, AOP.prototype); | |
} | |
} | |
AOP.prototype.before = function (property, fn) { | |
let oldProperty = this[property]; | |
this[property] = function () { | |
fn.apply(this, arguments); |
OlderNewer