Don’t simply test for the presence of the magic Paperclip attribute, it will return a paperclip Attachment object and thus always be true:
- if user.photo.present? # always true
= image_tag(user.photo.url)| # http://rspec.rubyforge.org/rspec/1.3.0/classes/Spec/Matchers.html#M000183 | |
| lambda { do_something_risky }.should raise_exception | |
| lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError) | |
| lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError) { |exception| exception.data.should == 42 } | |
| lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError, "that was too risky") | |
| lambda { do_something_risky }.should raise_exception(PoorRiskDecisionError, /oo ri/) | |
| lambda { do_something_risky }.should_not raise_exception | |
| lambda { do_something_risky }.should_not raise_exception(PoorRiskDecisionError) | |
| lambda { do_something_risky }.should_not raise_exception(PoorRiskDecisionError, "that was too risky") |
| # from https://github.com/ruby-china/ruby-china/blob/master/app/helpers/application_helper.rb | |
| MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' + | |
| 'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' + | |
| 'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' + | |
| 'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' + | |
| 'webos|amoi|novarra|cdm|alcatel|pocket|iphone|mobileexplorer|mobile' | |
| def mobile? | |
| agent_str = request.user_agent.to_s.downcase | |
| return false if agent_str =~ /ipad/ |
| RSpec.configure do |config| | |
| # ... | |
| end | |
| # quick hack to get Rack to be quiet about "warning: regexp match /.../n against to UTF-8 string" until we upgrade to Rails 3.1 with Rack 1.3 | |
| module Rack | |
| module Utils | |
| def escape(s) | |
| CGI.escape(s.to_s) |
| it "finds upcoming published lessons" do | |
| upcoming1 = Factory :lesson, start_at: 1.day.from_now | |
| upcoming2 = Factory :lesson, start_at: 2.days.from_now | |
| past = Factory :lesson, start_at: 1.day.ago | |
| draft = Factory :lesson, visibility: 'draft' | |
| Lesson.upcoming.should include(upcoming1, upcoming2) | |
| Lesson.upcoming.should_not include(past, draft) | |
| end |
| f = Nokogiri::XML.fragment(some_html_str) | |
| f.search('.//img').remove | |
| puts f.to_html |
| form html: { multipart: true } do |f| | |
| f.inputs "Basic Info" do | |
| # ... | |
| f.input :photo, as: :file | |
| end | |
| f.buttons | |
| end |
| # in gemfile i have these lines | |
| gem 'sitemap_generator', '2.0.1.pre1' | |
| gem 'carrierwave' | |
| gem 'fog' |
| # Say you have two columns: start_at, end_at | |
| # When start_at is defined, you want end_at's value based on the start_at | |
| # Here is the solution, passing a block to get the object of the context. | |
| start_at Random.new.rand(14..45).days.from_now | |
| end_at { |l| l.start_at + 2.hours } | |
| # Full example | |
| FactoryGirl.define do | |
| factory :lesson do |
| # check all your ENV vars. | |
| heroku config -long | |
| # add ENV vars | |
| heroku config:add S3_KEY=8N029N81 S3_SECRET=9s83109d3+583493190 |