feature "Posting a comment", js: true do
scenario "as signed user" do
comment_id = Comment.last.id + 1
within("#new_comment") do
fill_in 'comment[body]', with: 'コメントのテスト'
end
click_button '規約に同意してコメントする'
sleep 1 # PLZ WAIT!! FIXME!!
find("#comment_#{comment_id}").should have_content('コメントのテスト')
end
end
# Gemfile:
group :test do
gem 'poltergeist'
gem 'rack-contrib'
end
# spec/spec_helper.rb:
require 'capybara/poltergeist'
RSpec.configure do |config|
Capybara.javascript_driver = :poltergeist
end
# config/initializers/poltergeist.rb:
if Rails.env.test?
require 'rack/contrib/simple_endpoint'
Rails.application.config.middleware.insert_after Rack::Runtime, Rack::SimpleEndpoint, /\.ttf$/ do |req, res|
ua = req.env['HTTP_USER_AGENT']
if ua =~ /Intel Mac OS X.*PhantomJS/
res.status = 403
"Denying #{req.fullpath} to #{ua}"
else
:pass
end
end
end
Thrills and spills on the railway, it's a life of happiness
But sometimes impatience can lead to carelessness
Some think they are smart cats, and some just know it all
But sooner or later we all find out that
Accidents happen now and again, just when you least expect
Just when you think that life is okay, fate comes to collect
Accidents happen now and again, when people or trains get smart
If you don't concentrate on the thing that you're doing
Accidents will happen, just like that
Your best-laid plans can turn upside down if you get too confident
Sometimes you will slip and slide if that's Lady Luck's intent
One minute you're riding high, the next you're on the ground
But please remember, whatever the weather
You must take care 'cause
Accidents happen now and again, sometimes just by chance
You gotta pick yourself up and dust yourself down
Put it down to experience
Accidents happen now and again
Just don't take it all to heart
If you don't concentrate on the thing that you're doing
Accidents will happen, just like that
The warning signs are there for us to see most of the time
But sometimes we take chances and ignore the danger signs
Fate can surprise you, with no reason or rhyme
Make sure you learn your lesson you'll know better next time
Accidents happen now and again, just when you least expect
Just when you think that life is okay, fate comes to collect
Accidents happen now and again, when people or trains get smart
If you don't concentrate on the thing that you're doing
Accidents will happen, just like that
Accidents happen now and again
Sometimes just by chance
You gotta pick yourself up and dust yourself down
Put it down to experience
Accidents happen now and again
Just don't take it all to heart
If you don't concentrate on the thing that you're doing
And whatever you're doin' is not what you're thinking
Accidents, incidents
Accidents, incidents, accidents happen, just like that!
# app/models/comment.rb:
class Comment < ActiveRecord::Base
include ActsAsCommentable::Comment
belongs_to :commentable, polymorphic: true, counter_cache: true
end
# app/models/story.rb:
class Story < ActiveRecord::Base
has_many :comments, as: :commentable, dependent: :destroy
acts_as_commentable
attr_readonly :comments_count
end
# app/models/comic.rb:
class Comic < ActiveRecord::Base
has_many :comments, as: :commentable, dependent: :destroy
acts_as_commentable
attr_readonly :comments_count
end
Twitter.configure do |config|
config.consumer_key = YOUR_CONSUMER_KEY
config.consumer_secret = YOUR_CONSUMER_SECRET
config.oauth_token = YOUR_OAUTH_TOKEN
config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
end
module Twitter
module Configurable
attr_writer :consumer_key, :consumer_secret, :oauth_token, :oauth_token_secret
(...)
# Convenience method to allow configuration options to be set in a block
def configure
yield self
self
end
(...)
end