Skip to content

Instantly share code, notes, and snippets.

View sameera207's full-sized avatar

Sameera (Sam) sameera207

  • Sydney
View GitHub Profile
@sameera207
sameera207 / gist:4238451
Created December 8, 2012 03:27
testing with cucumber for logged user
http://stackoverflow.com/questions/13774022/testing-as-a-logged-in-user-in-rails
@sameera207
sameera207 / My Rails3 Testing setup
Created December 16, 2012 08:06
My Rails3 testing environment with Rspec, cucumber and guard and spork to keep the tests faster and automatic
==== Gem file
group :test, :development do
gem "rspec-rails", "~> 2.0"
gem 'database_cleaner'
gem 'capybara'
gem "factory_girl_rails", ">= 4.1.0"
gem 'cucumber-rails', :require => false
gem 'mocha'
gem "shoulda-matchers"
@sameera207
sameera207 / ROR validation callbacks
Created December 18, 2012 07:28
ROR validation callbacks
module (ROR validation callbacks)
== acceptance
class Person < ActiveRecord::Base
validates :terms_of_service, :acceptance => true
end
== validates_associated (* should not used on both ends)
@sameera207
sameera207 / ROR migrations
Created December 18, 2012 07:32
ROR migration cheat cheet
(ActiveRecord::Migration)
=== migration options
add_column
add_index
change_column
change_table
create_table
drop_table
---
rspec_shoulda: |
Shoulda Rspec Matchers
For more information on rspec, rspec-rails, shoulda
$ cheat rspec
$ cheat rspec_on_rails_matchers
$ cheat shoulda
Models Matchers
Data
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
sameeras-mbp:pretty_search sameera$ rspec
pretty search routes
. should route /pretty_search/query/company to pretty_search#search with model_name 'company'
PrettySearch::Query
constants
. check defaults
instance methods
.initialize
# encoding: utf-8
require 'logstash/codecs/base'
class LogStash::Codecs::JsonFileGz < LogStash::Codecs::Base
config_name 'json_file_gz'
milestone 1
public
def register
require 'zlib'
count = 0
a = Dir.glob("/<rails app path>/app/models/**/*.rb")
a.each do |f|
file = File.new(f)
@sameera207
sameera207 / gist:c0b9f89fa326bb23ff23
Last active August 29, 2015 14:05
Explanation for Regexp.new(search)
#Following is the problem with your solution. You have 2 if's , in ruby we need only 1 if
# notice that it has only one IF :)
if matched_games.length > 0 && matched_games.include?(search)
puts "Game #{search} found."
end
#clarrifications
Regexp.new(search) #is creating a new regular expression object in ruby.
#<Any Object>.new is the way of initializing an object in ruby. In this case 'Regexp' class.
#Regular expression can me used to match words in different options. Like