Skip to content

Instantly share code, notes, and snippets.

View JeanMertz's full-sized avatar

Jean Mertz JeanMertz

View GitHub Profile
# MODELS:
class Stencil < ActiveRecord::Base
has_one :stencil_config, :dependent => :destroy
accepts_nested_attributes_for :stencil_config
end
class StencilConfig < ActiveRecord::Base
belongs_to :stencil
end
# ERROR:
# _form.html.haml:25: syntax error, unexpected keyword_ensure, expecting keyword_end
# ...:Util.html_safe(_erbout);ensure;@haml_buffer = @haml_buffer....
# ... ^
# _form.html.haml:28: syntax error, unexpected $end, expecting keyword_end
#
# _form.html.haml:28: syntax error, unexpected $end, expecting keyword_end
#
= form_for([:admin, @stencil]) do |f|
# app/validators/domain_validator.rb
require "resolv"
class DomainValidator < ActiveModel::EachValidator
def validate_each(object,attribute,value)
begin
domain = Resolv::DNS.new.getresource(value, Resolv::DNS::Resource::IN::CNAME)
valid = true if domain.name.to_s == "mydomain.com"
rescue Exception => e
valid = false
end
# spec/controllers/users_controller_spec.rb
# ERROR:
# Failure/Error: get :edit, :id => user.id
# ActionController::RoutingError:
# No route matches {:id=>1, :controller=>"users", :action=>"edit"}
describe UsersController do
render_views
it "renders edit template for edit action" do
user = Factory(:user)
@JeanMertz
JeanMertz / syntax_highlighting.py
Created April 18, 2011 08:39
Ruby on Rails syntax highlight switcher for Sublime Text 2
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
def on_load(self, view):
filename = view.file_name()
theme = Factory.build(:theme)
temp_file = Tempfile.new('prefix', "#{Rails.root}/tmp")
temp_file << theme.html
temp_file.flush
theme.html = temp_file
# Scenario: Edit exsisting theme # features/admin_manage_themes.feature:15
# Given I already have a theme for the website # features/step_definitions/admin_manage_themes_steps.rb:27
# When I go to the edit theme page # features/step_definitions/admin_manage_themes_steps.rb:31
# And I modify the theme settings # features/step_definitions/admin_manage_themes_steps.rb:35
# Couldn't find Theme with ID=551 [WHERE ("themes".account_id = 1326)] (ActiveRecord::RecordNotFound)
# ./app/controllers/themes_controller.rb:25:in `update'
# <internal:prelude>:10:in `synchronize'
# (eval):2:in `click_button'
# ./features/step_definitions/form_steps.rb:10:in `/^I submit the "(\S+)" form$/'
# features/admin_manage_themes.feature:18:in `And I modify the theme settings'
@JeanMertz
JeanMertz / update_positions.rb
Created April 27, 2011 19:47
update_positions.rb
#PagesController
def update
@page = current_account.pages.find(params[:id], :readonly => false)
@page.update_attributes(params[:page])
end
#Page
before_update :change_positions, :if => :position_changed?
def change_positions
@JeanMertz
JeanMertz / children.rb
Created June 6, 2011 11:54
override children
def children(logged_in = true)
if logged_in
account.pages.where(parent_id: self.id)
else
account.pages.where(parent_id: self.id, is_active: true)
end
end
@page.children(logged_in?)
Feature: Authentication
In order to be able to manage my website
As a client of a designer using the service
I want to be able to log in and log out of my website backend
Background: Website exists with a user and I am on the login page
Given a "website" exists with name: "twitter"
And for that website, a "user" exists with email: "joe@twitter.dev" and password: "password123"
And for that website, a "domain" exists with name: "twitter-dev.manager.dev"
And for that website, a "domain" exists with name: "twitter.dev"