Created
August 25, 2011 16:23
-
-
Save ogredude/1171073 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="article"> | |
<div class="article-header"> | |
<%= title %> | |
</div> | |
<div class="article-content"> | |
<%= body %> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="block"> | |
<div class="block-header"> | |
<%= title %> | |
</div> | |
<div class="block-content"> | |
<%= body %> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def title(page_title) | |
content_for(:title) { h(page_title.to_s) } | |
end | |
def yield_for(content_sym,default = "") | |
output = content_for(content_sym) | |
output = default if output.blank? | |
output | |
end | |
# Block helper | |
def block_to_partial(partial_name, options = {}, &block) | |
options.merge!(:body => capture(&block)) | |
render(:partial => partial_name, :locals => options) | |
end | |
def block(title, options = {}, &block) | |
block_to_partial('layouts/block', options.merge(:title => title), &block) | |
end | |
def article(title, options = {}, &block) | |
block_to_partial('layouts/article', options.merge(:title => title), &block) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe ApplicationHelper do | |
context "yield_for" do | |
it "should regard the 'default' argument as optional" do | |
helper.content_for(:foo, "Testing") | |
helper.yield_for(:foo).should == "Testing" | |
end | |
it "should yield content specified by symbol" do | |
helper.content_for(:foo, "Testing") | |
helper.yield_for(:foo, "").should == "Testing" | |
end | |
it "should yield the default if no content in specified symbol" do | |
helper.yield_for(:bar, "Testing").should == "Testing" | |
end | |
it "should sanitize strings for HTML security" do | |
helper.content_for(:foo, "&<>") | |
helper.yield_for(:foo, "").should == "&<>" | |
end | |
end | |
context "title" do | |
it "should accept a block of text into content_for(:title)" do | |
helper.title("Testing") | |
helper.content_for(:title).should == "Testing" | |
end | |
end | |
context "Block Helper" do | |
it "should render the Block in a div structure" do | |
result = helper.block("Test Block") {"Test Block Content"} | |
result.should have_tag('div.block') do | |
with_tag 'div.block-header', :text => /Test Block/ | |
with_tag 'div.block-content', :text => /Test Block Content/ | |
end | |
end | |
end | |
context "Article Helper" do | |
it "should render the Article in a div structure" do | |
result = helper.article("Test Article") {"Test Article Content"} | |
result.should have_tag('div.article') do | |
with_tag 'div.article-header', :text => /Test Article/ | |
with_tag 'div.article-content', :text => /Test Article Content/ | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'http://rubygems.org' | |
gem 'rails', '3.0.9' | |
gem 'rake' | |
# Bundle edge Rails instead: | |
# gem 'rails', :git => 'git://github.com/rails/rails.git' | |
gem 'sqlite3' | |
gem 'mysql2', '0.2.7' | |
gem 'authlogic' | |
gem 'cancan' | |
# Use unicorn as the web server | |
# gem 'unicorn' | |
# Deploy with Capistrano | |
# gem 'capistrano' | |
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+) | |
# gem 'ruby-debug' | |
# gem 'ruby-debug19', :require => 'ruby-debug' | |
# Bundle the extra gems: | |
# gem 'bj' | |
# gem 'nokogiri' | |
# gem 'sqlite3-ruby', :require => 'sqlite3' | |
# gem 'aws-s3', :require => 'aws/s3' | |
# Bundle gems for the local environment. Make sure to | |
# put test-only gems in this group so their generators | |
# and rake tasks are available in development mode: | |
# group :development, :test do | |
# gem 'webrat' | |
# end | |
group :development, :test do | |
gem 'rspec-rails' | |
gem 'shoulda-matchers' | |
gem 'factory_girl_rails', :require => false | |
gem 'faker' | |
gem 'watchr' | |
gem 'ruby-debug' | |
gem 'rspec2-rails-views-matchers' | |
# gem 'jasmine' | |
gem 'capybara', '~> 1.0.0' | |
gem 'capybara-webkit' | |
gem 'launchy' | |
gem 'database_cleaner' | |
gem 'syntax' | |
end | |
group :test do | |
gem 'spork', '~> 0.9.0.rc' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Helpers | |
def sign_in(user) | |
@user_session = UserSession.create user | |
end | |
def fill_in_autocomplete(selector, value) | |
page.execute_script %Q{$('#{selector}').val('#{value}').keydown()} | |
end | |
def choose_autocomplete(text) | |
find('ul.ui-autocomplete').should have_content(text) | |
page.execute_script("$('.ui-menu-item:contains(\"#{text}\")').find('a').trigger('mouseenter').click()") | |
end | |
def wait_for_animation | |
wait_until do | |
page.evaluate_script('$(":animated").length') == 0 | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'spork' | |
require 'spec/helpers' | |
Spork.prefork do | |
# Loading more in this block will cause your tests to run faster. However, | |
# if you change any configuration or code from libraries loaded here, you'll | |
# need to restart spork for it take effect. | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
Capybara.javascript_driver = :webkit | |
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} | |
RSpec.configure do |config| | |
config.mock_with :rspec | |
# config.fixture_path = "#{::Rails.root}/spec/fixtures" | |
# config.use_transactional_fixtures = true | |
config.use_transactional_fixtures = false | |
config.before :each do | |
if example.metadata[:js] | |
DatabaseCleaner.strategy = :truncation | |
else | |
DatabaseCleaner.strategy = :transaction | |
end | |
DatabaseCleaner.start | |
end | |
config.after do | |
DatabaseCleaner.clean | |
end | |
config.include Helpers | |
end | |
# Needed for Spork | |
ActiveSupport::Dependencies.clear | |
end | |
Spork.each_run do | |
# This code will be run each time you run your specs. | |
require 'factory_girl_rails' | |
load "#{Rails.root}/config/routes.rb" | |
Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f } | |
end | |
require 'authlogic/test_case' | |
include Authlogic::TestCase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment