Skip to content

Instantly share code, notes, and snippets.

View szymon-przybyl's full-sized avatar

Szymon Przybył szymon-przybyl

View GitHub Profile
class Game
include Mongoid::Document
def self.my_method
puts "test"
end
end
class Deer < Game
my_method
specify 'with product_quantity greater than associated product quantity' do
Factory(:order,
:product => Factory(:product, :quantity => 10),
:product_quantity => 11
).should have(1).error_on(:product_quantity)
end
class Order < ActiveRecord::Base
belongs_to :product
belongs_to :user
validates_presence_of :user, :product, :product_quantity
validates_numericality_of :product_quantity,
:only_integer => true, :greater_than => 0, :less_than_or_equal_to => 10000, :allow_blank => true
validate :enough_product_quantity,
# if does not work
@szymon-przybyl
szymon-przybyl / gist:1078859
Created July 12, 2011 20:10
UsersConroller#create spec
describe 'POST create' do
context 'with valid params' do
before(:each) { User.any_instance.stub!(:valid?).and_return(true) }
it 'creates new user and redirects to the home page with a notice' do
post :create, :user => Factory.attributes_for(:user, :username => 'dude')
assigns[:user].should be_persisted
assigns[:user].username.should eq('dude')
flash[:notice].should_not be_nil
response.should redirect_to(root_url)
end
class LocatorController < ApplicationController
def autocomplete
require 'net/http'
require 'net/https'
url = URI.parse 'https://maps.googleapis.com/maps/api/place/autocomplete/json?language=pl&input=Polichno&sensor=false&key=ABQIAAAAHyX2ujLFqkeXszJQ65ZPbhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTCcRPSPSwcyYGhNTuA3d46XxgyQg'
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
req = Net::HTTP::Get.new(url.path)
res = http.request(req)
puts res
new Ajax.Request('https://maps.googleapis.com/maps/api/place/autocomplete/json', {
method: 'get',
parameters: {
language: 'pl',
input: 'Polichno',
sensor: true,
key: 'ABQIAAAAHyX2ujLFqkeXszJQ65ZPbhQCULP4XOMyhPd8d_NrQQEO8sT8XBQKE5E92FkCP2ATUaYPiLb3YFfVzg'
},
onSuccess: function(transport, json) {
alert(json ? Object.inspect(json) : 'no JSON object');
def self.roots
where(:parent_id => nil)
end
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
require 'uri'
require 'cgi'
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
= form_for(@movie) do |f|
= f.label :title
= f.text_field :title
= f.label :release_year
= f.select :release_year, (1900..2011).to_a.map(&:to_s)
- @genres.each do |genre|
%label
=h genre.name
= check_box_tag 'genres[]', genre.id
= f.submit 'Save'
class MoviesController < ApplicationController
def index
end
def new
@movie = Movie.create
@genres = Genre.all
end
def create