Skip to content

Instantly share code, notes, and snippets.

View bogdan's full-sized avatar

Bogdan Gusiev bogdan

View GitHub Profile
class Inspiration < Feedback
belongs_to :user
belongs_to :group
belongs_to :inspired_group, :class_name => "Group", :foreign_key => "inspired_group_id"
#Will Paginate
cattr_reader :per_page
@@per_page = 10
end
class SearchController < ApplicationController
def index
case params[:show]
when 'people'
search_scope = [User]
when 'projects'
search_scope = [Project]
else
search_scope = [User, Project]
end
class SearchesController < ApplicationController
def show
@search = Post.search do
if params[:q].present?
keywords(params[:q]) do
highlight :body
end
end
if params[:cat].present?
with(:category_id, params[:cat].to_i)
describe "named scope" do
describe "#similar_to" do
let(:category) { Factory.create(:category) }
let(:product) {
Factory.create(
:product, :categories => [category]
)
require "webrat/core/save_and_open_page"
require "webrat/selenium/selenium_rc_server"
require "webrat/selenium/application_server_factory"
require "webrat/selenium/application_servers/base"
require "selenium"
module Webrat
class TimeoutError < WebratError
end
def construct_sql
case
when @reflection.options[:finder_sql]
@finder_sql = interpolate_sql(@reflection.options[:finder_sql])
when @reflection.options[:as]
@finder_sql =
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id = #{owner_quoted_id} AND " +
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}"
@finder_sql << " AND (#{conditions})" if conditions
class Game < ActiveRecord::Base
include ProductsStateMachine
include ProductsRating
include Commentable
include GamesAndMusicMethods
include VideoAttachable
belongs_to :company
belongs_to :genre
has_many :game_files, :dependent => :destroy, :validate => true, :autosave => true
has_many :activation_codes
def current_user(author = false)
# Create new test user
unless @current_user
user = Factory.create(:user)
if author
Factory.create(:contributor, :user => user)
end
@current_user = User.find(user.id)
end
@current_user
after_update do |m|
m.album.update_attribute(:band_id, m.band_id) if m.album.is_a?(Single) && m.band_id_changed?
if m.audio_id_changed? && m.audio_id.present? # audio => audio
audio = Audio.find( m.old_audio_id )
if audio.is_a?( Single ) # single => album
audio.destroy
end
end
true
end
class RenameAlbumsToAudios < ActiveRecord::Migration
def self.up
rename_table :albums, :audios
end
def self.down
rename_table :audios, :albums
end
end