Skip to content

Instantly share code, notes, and snippets.

@jferris
Forked from aroop/factories.rb
Created July 22, 2011 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jferris/1100022 to your computer and use it in GitHub Desktop.
Save jferris/1100022 to your computer and use it in GitHub Desktop.
Factory.define :gallery do |f|
f.name "Gallery Name"
end
Factory.define :region do |f|
f.name "Telugu"
end
class GalleriesController < MoviesBaseController
has_scope :rated, :type => :boolean
has_scope :recent, :type => :boolean
has_scope :starts_with
optional_belongs_to :celebrity, :movie, :event, :polymorphic => true
actions :index
def show
redirect_to gallery_photos_path(resource)
end
end
class GalleriesSweeper < ActionController::Caching::Sweeper
include MekosamSweeper
observe Gallery
def resource_name
"galleries"
end
def clear_associations(resource)
clear_standard_associations(resource)
resource.photos.each { |photo| PhotosSweeper.instance.expire_cached_ui(photo) }
end
def clear_front_page_content(resource, force = false)
# TODO Need to implement force, searching in regions for better performance of front page
Rails.cache.delete_matched(".*home_sidebar_recent_articles.*")
end
end
module MekosamSweeper
def expire_cached_collection(resource)
update_materialized_view(resource)
clear_front_page_content(resource, true)
clear_associations(resource)
# Delete all index pages
Rails.cache.delete_matched(collection_key(resource))
clean_show_page(resource)
end
def expire_cached_resource(resource)
update_materialized_view(resource)
expire_cached_ui(resource)
clear_associations(resource)
end
def expire_cached_ui(resource)
puts "In expire_cached_ui for #{resource.class} #{resource.id}"
clear_front_page_content(resource)
keys = Rails.cache.instance_variable_get(:@data).keys(collection_key(resource))
keys.each do |key|
Rails.cache.delete(key) if Rails.cache.read(key).include?(resource_link(resource))
end
clean_show_page(resource)
end
alias_method :after_save, :expire_cached_resource
alias_method :after_create, :expire_cached_collection
alias_method :after_destroy, :expire_cached_collection
end
require 'spec_helper'
describe "ShowGalleries" do
before :each do
@current_region = Factory(:region)
end
describe "GET /gallery" do
it "should redirect to photos index path" do
gallery = Factory(:gallery)
visit gallery_path(gallery)
current_path.should eq(gallery_photos_path(gallery))
end
end
end
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require File.dirname(__FILE__) + "/factories"
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment