Skip to content

Instantly share code, notes, and snippets.

View Fire-Dragon-DoL's full-sized avatar

Francesco Belladonna Fire-Dragon-DoL

View GitHub Profile
class Ability
include CanCan::Ability
def initialize(user)
@user = user || User.new # for guest
guest
administrator if user.is_admin?
end
def guest
# POST /offers
# POST /offers.json
def create
@offer = Offer.new(offer_params)
@offer.offer_timestamp = Time.zone.now
@offer.user = current_user
respond_to do |format|
if @offer.save
format.html { redirect_to [@offer.product, @offer], notice: 'Offer was successfully created.' }
D:\wamp\www\austin\austinparker_it>gem uninstall zentest
Invalid gemspec in [D:/Programs/Ruby/Ruby193_362/lib/ruby/gems/1.9.1/specifications/ZenTest-4.9.0.gemspec]: Illformed requirement ["< 2.1, >= 1.8"]
Invalid gemspec in [D:/Programs/Ruby/Ruby193_362/lib/ruby/gems/1.9.1/specifications/ZenTest-4.9.0.gemspec]: Illformed requirement ["< 2.1, >= 1.8"]
INFO: gem "zentest" is not installed
@Fire-Dragon-DoL
Fire-Dragon-DoL / pages_spec.rb
Last active December 13, 2015 17:39
This test doesn't pass (last one)
require 'spec_helper'
describe "Pages" do
describe "Testing locale" do
describe "GET /en" do
it "should have english text" do
visit '/en'
page.should have_content('Hello')
end
end
@Fire-Dragon-DoL
Fire-Dragon-DoL / user_spec.rb
Created February 14, 2013 03:06
How to test sign_in method?
require 'spec_helper'
describe 'Users' do
describe 'Login' do
it 'should login the user and show logout link' do
user = FactoryGirl.create(:user)
visit new_user_session_path
fill_in 'Email', with: user.email
fill_in 'Password', with: user.password
click_button 'Sign in'
FactoryGirl.define do
factory :tech_spec_name do
sequence(:name) { |n| "#{ Faker::Lorem.word } #{ n }"}
end
factory :boat do
name { Faker::Name.first_name }
end
factory :tech_spec do
FactoryGirl.define do
factory :tech_spec_name do
sequence(:name) { |n| "#{ Faker::Lorem.word } #{ n }"}
end
factory :boat do
name { Faker::Name.first_name }
end
factory :tech_spec do
class TechSpec < ActiveRecord::Base
validates :boat_id, presence: true
validates :tech_spec_name_id, presence: true, uniqueness: { scope: :boat_id }
belongs_to :boat
belongs_to :tech_spec_name
acts_as_list scope: :boat
def as_json(options = {})
@Fire-Dragon-DoL
Fire-Dragon-DoL / admin_controller.rb
Created February 19, 2013 18:34
Rails Admin Controller
class AdminController < ApplicationController
layout 'admin'
end
@Fire-Dragon-DoL
Fire-Dragon-DoL / trips_controller.rb
Created February 19, 2013 23:17
Gist showing kaminari functionality
class TripsController < ExtjsController
def viewer
if true # Ok qua non c'era questa if ma non mi va di andare a prendere in cima quella giusta
# ... Lunghissima e inutile configurazione della query...
@trips = Trip.joins(table_join_to_cache)
.where(trips_find_condition_values)
.uniq.order('begin_date ASC, title ASC')
.page(params[:page])