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
MyApplication::Application.configure do | |
config.ingredient_api_url = "http://example.com" | |
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
class Ingredient < ActiveResource::Base | |
self.site = MyApplication::Application.config.ingredient_api_url | |
self.format = :json | |
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
Rails.application.routes.draw do | |
resources :ingredients, :only => [:index, :show] | |
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
class IngredientsController < ApplicationController | |
respond_to :json | |
def index | |
respond_with Ingredient.all | |
end | |
def show | |
respond_with Ingredient.find(params[:id]) |
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
class Ingredient < ActiveRecord::Base | |
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
class IngredientsController < ApplicationController | |
caches_action :index, :show | |
cache_sweeper :ingredients_sweeper | |
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
class IngredientsSweeper < ActionController::Caching::Sweeper | |
observe Ingredient | |
def after_save(record) | |
expire_action :controller => "ingredients", | |
:action => "index", | |
:format => :json | |
expire_action :controller => "ingredients", | |
:action => "show", |
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 'fakeweb' | |
# this can also be set to a regular expression to whitelist URI's | |
FakeWeb.allow_net_connect = false | |
def load_fixture(name) | |
path = "#{Rails.root}/features/fixtures/#{name}.rb" | |
eval File.open(path).map { |line| line }.join("") | |
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
[ | |
{ | |
"id" => 1, | |
"name" => "sassafras" | |
} | |
] |
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
# instead of { "my_model": { "id": 1, "title": "foo" } } | |
# to_json produces { "id": 1, "title": "foo" } | |
ActiveRecord::Base.include_root_in_json = false |
OlderNewer