$ rails g model User
belongs_to
has_one
| =Navigating= | |
| visit('/projects') | |
| visit(post_comments_path(post)) | |
| =Clicking links and buttons= | |
| click_link('id-of-link') | |
| click_link('Link Text') | |
| click_button('Save') | |
| click('Link Text') # Click either a link or a button | |
| click('Button Value') |
| # RSpec's subject method, both implicitly and explicitly set, is useful for | |
| # declaratively setting up the context of the object under test. If you provide a | |
| # class for your describe block, subject will implicitly be set to a new instance | |
| # of this class (with no arguments passed to the constructor). If you want | |
| # something more complex done, such as setting arguments, you can use the | |
| # explicit subject setter, which takes a block. | |
| describe Person do | |
| context "born 19 years ago" do | |
| subject { Person.new(:birthdate => 19.years.ago } | |
| it { should be_eligible_to_vote } |
| #!/bin/bash | |
| # This script does the following: | |
| # 1/ capture and download the latest backup | |
| # 2/ load it to your local database | |
| # 3/ run your app and open Safari | |
| # Just replace any uppercase string with your own data | |
| # |
| def get_movie_duration video_file | |
| # Run ffmpeg on the video, and do it silently | |
| ffmpeg_output = `/usr/local/bin/ffmpeg -i "#{video_file}" 2>&1` | |
| # Find the duration in the output, and force a return if it's found | |
| /duration: ([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2})/i.match(ffmpeg_output) { |m| return m[1] } | |
| # If it didn't get a match, something is wrong. Log the error | |
| return "FFMPEG ERROR" |
| # (v.respond_to?(:empty?) ? v.empty? : !v) is basically rails' .blank? in plain ruby | |
| class Hash | |
| def delete_blank | |
| delete_if do |k, v| | |
| (v.respond_to?(:empty?) ? v.empty? : !v) or v.instance_of?(Hash) && v.delete_blank.empty? | |
| end | |
| end | |
| end |
| # app/models/ability.rb | |
| # All front end users are authorized using this class | |
| class Ability | |
| include CanCan::Ability | |
| def initialize(user) | |
| user ||= User.new | |
| can :read, :all |
| class ChangeCalculator | |
| QUARTER = 0.25 | |
| DIME = 0.10 | |
| NICKEL = 0.05 | |
| PENNY = 0.01 | |
| COINS = [QUARTER, DIME, NICKEL, PENNY] | |
| def calculate(x) | |
| remaining = x | |
| $h = COINS.inject({}) do |hash, coin| |
| #Model | |
| @user.should have(1).error_on(:username) # Checks whether there is an error in username | |
| @user.errors[:username].should include("can't be blank") # check for the error message | |
| #Rendering | |
| response.should render_template(:index) | |
| #Redirecting | |
| response.should redirect_to(movies_path) |
Periodically use pgbackups to pull latest production data.
Merge master into staging
git checkout master
git reset --hard origin/master
git pull
git checkout staging
git reset --hard origin/staging