Skip to content

Instantly share code, notes, and snippets.

@endash
Created January 5, 2012 18:42
Show Gist options
  • Save endash/1566585 to your computer and use it in GitHub Desktop.
Save endash/1566585 to your computer and use it in GitHub Desktop.
it "Should expire when I approve a pending Airport" do
user = Factory(:user, :login => 'cacheing', :password => 'specs', :admin => true)
Airport.delete_all
Rails.cache.clear
@airport1 = Factory(:airport, :aasm_state => 'approved', :has_schedule => true)
@airport2 = Factory(:airport, :aasm_state => 'pending', :has_schedule => true)
login_via_session('cacheing', 'specs')
get '/airports.json?api_version=2'
response.should be_success
puts "first load"
puts response.body
parsed_body = JSON.parse(response.body)
parsed_body.should be_kind_of(Array)
parsed_body.size.should == 1
parsed_body[0]['airport'].should be_kind_of(Hash)
parsed_body[0]['airport']['id'].should == @airport1.id
# Check for the cache expiration
Rails.cache.should_receive(:delete).with("views/www.example.com/airports", anything())
Rails.cache.should_receive(:delete).with("views/www.example.com/airports.json", anything())
Rails.cache.should_receive(:delete).with("views/www.example.com/airports.xml", anything())
Rails.cache.should_receive(:delete).with(/views\/www\.example\.com\/airports\/[\d]+$/, anything())
Rails.cache.should_receive(:delete).with(/views\/www\.example\.com\/airports\/[\d]+\.json$/, anything())
Rails.cache.should_receive(:delete).with(/views\/www\.example\.com\/airports\/[\d]+\.xml$/, anything())
# Build attributes for the ActiveScaffold create (must match attributes from AS config)
headers = http_auth_header('cacheing', 'specs')
put '/panel/airports/' + @airport2.id.to_s + '/approve', nil, headers
response.should be_success
@airport2.reload
@airport2.aasm_state.should == "approved"
get '/airports', nil, 'HTTP_ACCEPT' => 'application/json;version=2'
response.should be_success
puts "second load"
puts response.body
parsed_body = JSON.parse(response.body)
parsed_body.should be_kind_of(Array)
parsed_body.size.should == 2
parsed_body[0]['airport'].should be_kind_of(Hash)
parsed_body[0]['airport']['id'].should == @airport1.id
parsed_body[1]['airport'].should be_kind_of(Hash)
parsed_body[1]['airport']['id'].should == @airport2.id
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment