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
def new_test_user(args={}) | |
i = rand(9999) | |
random_string = (Time.now.strftime("%s").to_i-i) | |
final_params = {:password => "testp", | |
:login => random_string, | |
:password_confirmation => "testp", | |
:email => "#{random_string}@gmg-entertainment.com"}.merge!(args) | |
User.create!(final_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
require File.dirname(__FILE__) + '/../test_helper' | |
class UsersTest < ActiveSupport::TestCase | |
fixtures :roles, :partners | |
def setup | |
@u_admin = new_test_user(:role => roles(:admin), :partner => partners(:other)) | |
@u_other = new_test_user(:role => roles(:other), :partner => partners(:other)) | |
@u_admin_gmg = new_test_user(:role => roles(:admin), :partner => partners(:gmg)) |
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 'socket' | |
require 'openssl' | |
require 'net/ftp' | |
class Net::FTPS < Net::FTP | |
end | |
class Net::FTPS::Implicit < Net::FTP | |
FTP_PORT = 990 |
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
function unique(a) | |
{ | |
var r = []; | |
o:for(var i = 0, n = a.length; i < n; i++) { | |
for(var x = i + 1 ; x < n; x++) | |
{ | |
if(a[x]==a[i]) {continue o;} | |
} | |
r[r.length] = a[i]; | |
} |
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 Blog | |
require 'open-uri' | |
require 'rss' | |
def self.latest | |
@blog ||= load_blog | |
end | |
protected |
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
# CLOSURES IN RUBY Paul Cantrell http://innig.net | |
# Email: username "cantrell", domain name "pobox.com" | |
# I recommend executing this file, then reading it alongside its output. | |
# | |
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments, | |
# then trying to guess the output of the code! | |
# A closure is a block of code which meets three criteria: | |
# |
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 Mod | |
def self.ago(seconds) | |
case true | |
when seconds.to_i < 60 | |
s = seconds.to_i | |
return "#{s} second#{s>1 ? "s" : ""} ago." | |
when seconds.to_i < 3600 | |
m = seconds.to_i/60 | |
s = seconds.to_i%60 |
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 'test_helper' | |
class ModTest < ActiveSupport::TestCase | |
test "ago function" do | |
assert_equal "1 second ago.", Mod.ago(1) | |
assert_equal "40 seconds ago.", Mod.ago(40) | |
assert_equal "1 minute, 1 second ago.", Mod.ago(61) | |
assert_equal "3 minutes, 1 second ago.", Mod.ago(181) | |
assert_equal "2 minutes, 40 seconds ago.", Mod.ago(160) | |
assert_equal "1 hour, 3 minutes, 1 second ago.", Mod.ago(3600 + 181) |
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
def to_boolean(value, nil_value = false) | |
value.downcase! if value.class == String | |
case value | |
when "no","false",false, "0", 0 | |
false | |
when "yes","true",true, "1", 1 | |
true | |
when nil | |
nil_value | |
else |
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 Extensions | |
module ActiveRecord | |
# Understands how to generate counts and entries for the given scope, and offers some reasonable | |
# pagination helper methods. | |
class Paginator | |
attr_reader :count, :entries, :page, :per_page | |
def initialize(scope, opts={}) | |
@page = opts[:page].try(:to_i) || first_page | |
@per_page = opts[:per_page].try(:to_i) || scope.proxy_scope.per_page |
OlderNewer