Skip to content

Instantly share code, notes, and snippets.

View zealoushacker's full-sized avatar

Alex Notov zealoushacker

View GitHub Profile
@zealoushacker
zealoushacker / gist:1016312
Created June 9, 2011 08:20 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@zealoushacker
zealoushacker / take_attendance.feature
Created July 13, 2011 17:08
Taking attendance scenario
@multiple_students @selenium
Scenario: Taking attendance for multiple students with default settings
When I select 3 students
And I press "Take Attendance"
Then students 1..3 should have 1 less credits
And I should see "3 classes recorded"
Then /^student (\d+|\d+..\d+) should have (\d+) less credits$/ do |student_num, num_credits|
if student_num =~ /\d+..\d+/
student_num.to_range.each do |s_id|
tr_locator = "table#customer_users tbody tr:nth-of-type(#{s_id})"
selenium.get_text("css=#{tr_locator} td:nth-of-type(4)").should == (@cu.credits_active - num_credits.to_i).to_s
selenium.get_text("css=#{tr_locator} td:nth-of-type(5)").should == (@cu.attended + 1).to_s
end
else
@zealoushacker
zealoushacker / row_col_val_matcher.rb
Created July 13, 2011 17:13
Row+column/value matcher
Then /^row (\d+) column (\d+) of table "([^"]*)" should be "([^"]*)"$/ do |row,column,table_id,value|
locator = "css=table##{table_id} tbody tr:nth-of-type(#{row}) td:nth-of-type(#{column})"
selenium.get_text(locator).should == value
end
@zealoushacker
zealoushacker / table_values_matcher.rb
Created July 13, 2011 17:14
Table values matcher
Then /^table "([^"]*)" should have the values:$/ do |table_id, table|
table.hashes.each do |row|
Then %{row #{row[:row]} column #{row[:col]} of table "#{table_id}" should be "#{row[:value]}"}
end
end
Then table "business_services" should have the values:
| row | col | value |
| 1 | 1 | Unlimited Class Card |
| 1 | 2 | ul |
| 1 | 3 | $100.00 |
@zealoushacker
zealoushacker / better_table_step.feature
Created July 13, 2011 17:16
Better table matching step
Then table "business_services" should look like:
| field 1 | field 2 | field 3 |
| x | y | z |
| a | b | c |
<!DOCTYPE html>
<html>
<head>
<title>Site</title>
</head>
<body class="app">
<%= render :partial => 'layouts/flashes' %>
<%= yield %>
</body>
</html>
# Allow RSpec assertions over the elements of a collection. For example:
#
# collection.should all_be > 0
#
# will specify that each element of the collection should be greater
# than zero. Each element of the collection that fails the test will
# be reported in the error message.
#
# Examples:
# [1,1,1].should all_be eq(1)
@zealoushacker
zealoushacker / sq_cat.js
Created August 1, 2011 20:24
A meowing Cat FTW!
var SQAPP = {};
SQAPP.Cat = function ( name ) {
this.name = name;
}
SQAPP.Cat.prototype.meow = function () {
alert(this.name + " says meow!");
}