Created
July 22, 2011 17:28
-
-
Save aroop/1099913 to your computer and use it in GitHub Desktop.
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
Factory.define :gallery do |f| | |
f.name "Gallery Name" | |
end | |
Factory.define :region do |f| | |
f.name "Telugu" | |
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 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 |
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 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 |
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 Gallery < ActiveRecord::Base | |
include Sluggable, Searchable | |
validates_presence_of :name | |
has_many :gallery_associations, :dependent => :destroy | |
has_many :photos, :order => "position", :dependent => :destroy | |
has_many :celebrities, :through => :gallery_associations | |
has_many :movies, :through => :gallery_associations | |
has_many :events, :through => :gallery_associations | |
scope :recent, :order => "created_at DESC" | |
scope :starts_with, proc { |filter| { :conditions => ["name ILIKE ?", "#{filter}%"] } } | |
scope :rated, :order => "rating_average DESC" | |
def self.region(region) | |
region_id = region.instance_of?(Fixnum) ? region : Region.find(region).id | |
joins("join galleries_by_region on galleries_by_region.gallery_id = #{quoted_table_name}.id AND galleries_by_region.region_id = #{region_id}") | |
end | |
def preview_image | |
photos.first.try(:image) | |
end | |
ajaxful_rateable :stars => 5 | |
tankit 'mekosam' do | |
indexes :name | |
indexes :description | |
end | |
after_save do |record| | |
record.celebrities.each(&:touch) | |
record.movies.each(&:touch) | |
record.events.each(&:touch) | |
end | |
rails_admin do | |
edit do | |
field :name | |
field :description | |
field :event_date | |
field :celebrities | |
field :movies | |
field :events | |
end | |
list do | |
field :name | |
field :description | |
field :event_date | |
field :options do | |
css_class "action edit" | |
formatted_value do | |
bindings[:view].content_tag(:a, "Manage photos", :href => "/admin/gallery/#{bindings[:object].id}") | |
end | |
end | |
end | |
end | |
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
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 |
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 '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 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
# 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