Skip to content

Instantly share code, notes, and snippets.

View mhfs's full-sized avatar

Marcelo Silveira mhfs

View GitHub Profile
class NFE < ActiveRecord::Base
validates_presence_of :service_value
usar_como_dinheiro :service_value
end
# >> n = NFE.new
# >> n.service_value = 10
# => 10
# >> n.valid?
# => true
# Each time a failed authentication attempt happens we call the lockable handlers
Warden::Manager.before_failure do |record, warden, options|
if record && record.respond_to?(:active?) && !record.active?
scope = options[:scope]
# If winning strategy was set, this is being called after authenticate and
# there is no need to force a redirect.
if warden.winning_strategy
warden.winning_strategy.fail!(record.inactive_message)
else
# This declaration ..
semantic_menu :class => "top_level_nav" do |root|
root.add "Home", root_path
root.add "Settings", settings_path do |settings|
settings.add "Users", users_path, :activate_for_deeper_paths => true
end
end
# .. would make the "Users" item active for all this URIs
class Users::TaskListsController < InheritedResources::Base
defaults :route_prefix => ''
before_filter :authenticate_user!
belongs_to :user
protected
def begin_of_association_chain
@current_user
end
end
describe "As a visitor I want to be able to signup" do
def visit_and_fill_signup_form(valid = true)
visit root_url
click_link "Sign Up"
fill_in "Name", :with => "Test User"
fill_in "Email", :with => "[email protected]"
fill_in "Password", :with => "123mudar"
fill_in "Password Confirmation", :with => "123mudar" if valid
click_button "Save"
As a Provider
I want to be able sign up
So that I can can receive Rails project referrals
Scenario: Signing up with an invalid password confirmation
Given I am on the homepage
And I follow "provider.signup" translation
And I fill in the provider sign up form for "Pivotpaul Labs"
And I fill in the "First name" with "JD"
And I fill in the "Last name" with "Crow"
describe "As a visitor I want to be able to signup and login" do
it "should sign up with valid params" do
visit root_url
click_link "Sign Up"
fill_in "Name", :with => "Test User"
fill_in "Email", :with => "[email protected]"
fill_in "Password", :with => "123mudar"
fill_in "Password Confirmation", :with => "123mudar"
click_button "Save"
def index
@assets = current_account.assets.paginate :page => params[:page], :per_page => 10
end
# How to spec this???
def factories(*models)
models.each do |model|
(class << self; self; end).class_eval <<-METHOD
def factory_#{model}
@#{model} ||= Factory(:#{model})
end
METHOD
self.class_eval <<-METHOD
def factory_#{model}
require File.dirname(__FILE__) + '/../spec_helper'
describe AccountController do
as_any_user :get => :show do
it { should assign_to(:user, :with => @current_user)}
it { should respond_with(:success) }
end
as_any_user :get => :edit do
it { should assign_to(:user, :with => @current_user)}