Skip to content

Instantly share code, notes, and snippets.

View tpendragon's full-sized avatar

Trey Pendragon tpendragon

  • Princeton University Library
  • Salem, OR
View GitHub Profile
<%= form_tag products_path, method: :get do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", title: nil %>
</p>
<% end %>
## I need to have a Group that can consist of Users and/or Companies
class User
has_many :relationships
has_many :companies, :through => :relationships
has_many :groups, :as => :groupable
end
class Relationships
belongs_to :user
class Carnivore < Player
before_save :set_lvl
def initialize(attributes = {})
super
self.xp = 0
self.max_xp = 50
self.hp = 5
self.max_hp = 5
self.ap = 3
class TournamentEntry < ActiveRecord::Base
attr_accessible :entry_reqs, :format, :future, :links, :location, :name, :ongoing, :past, :prizes, :sponsor :status
# attr_accessor :status
def status
if !self.future.blank?
return "future"
elsif !self.ongoing.blank?
return "ongoing"
elsif !self.past.blank?
# before, would depend on routing constraints to block .json/.xml as 404 not found
class ThingyController < ApplicationController
def show
@thingy = Thingy.find params[:id]
end
def update
@thingy = Thingy.find params[:id]
class UpdateCache < ActiveRecord::Migration
def up
User.all.each do |user|
User.reset_counters(user.id, :pets)
end
end
def down
end
end
require 'spec_helper'
describe Car do
let(:manufacturer) { FactoryGirl.create(:manufacturer)}
let(:car) { FactoryGirl.create(:car, manufacturer: manufacturer)}
it "basic_articles with no extras required" do
basic_article = FactoryGirl.create(:basic_article, requires_extra: false)
expect(manufacturer.selectable_cars.count).to eq(1)
end
@tpendragon
tpendragon / search.rb
Last active December 26, 2015 03:39 — forked from Viswanathantv/search
class MainsController < ApplicationController
def index
[City, State, Country].each do |klass|
@search = klass.search(params[:q])
@result = @search.result
break unless @result.blank?
end
end
Run options: include {:locations=>{"./spec/controllers/shelters_controller_spec.rb"=>[61]}}
SheltersController
Fails to PATCH update when submitting invalid data
"#<ActiveModel::Errors:0x00000005446ad8 @base=#<Shelter id: 1, name: nil, phone_number: \"606-555-1212\",
contact_person: \"Shelter Contact\", rescue_group_id: nil, created_at: \"2013-12-27 20:33:10\",
updated_at: \"2013-12-27 20:33:10\">, @messages={:name=>[\"can't be blank\"]}>"
"#<ActionDispatch::Flash::FlashHash:0x000000068fdd28 @discard=#<Set: {}>,
@flashes={:notice=>\"Successfully updated Shelter!\"}, @now=nil>"
fails to update a shelter with bad info
require 'spec_helper'
describe Project do
let!(:user) { FactoryGirl.create(:user) }
let!(:plan) { FactoryGirl.create(:plan_with_subscription, user: user) }
it "has a valid factory" do
FactoryGirl.create(:project, user: user). should be_valid
end