Merge branch 'master' of github.com:Rulingcom/NCCU
This commit is contained in:
		
						commit
						af4865ceb7
					
				|  | @ -32,7 +32,7 @@ class Admin::PurchasesController < ApplicationController | ||||||
|      |      | ||||||
|     public_key = OpenSSL::PKey::RSA.new(File.read(APP_CONFIG['main_public_key'])) |     public_key = OpenSSL::PKey::RSA.new(File.read(APP_CONFIG['main_public_key'])) | ||||||
|     encrypted_data = public_key.public_encrypt({:purchase_id => purchase.purchase_id, |     encrypted_data = public_key.public_encrypt({:purchase_id => purchase.purchase_id, | ||||||
|                                                 :purchase_type => purchase._type, |                                                 :purchase_type => purchase.class.to_s, | ||||||
|                                                 :roaming_id => Site.find(session[:site]).roaming_id, |                                                 :roaming_id => Site.find(session[:site]).roaming_id, | ||||||
|                                                 :url => url}.to_json) |                                                 :url => url}.to_json) | ||||||
|      |      | ||||||
|  | @ -43,7 +43,7 @@ class Admin::PurchasesController < ApplicationController | ||||||
|     temp_file.write response.body |     temp_file.write response.body | ||||||
|     temp_file.rewind |     temp_file.rewind | ||||||
|     zip_name = response['content-disposition'].split('filename=')[1].gsub(/[\\\"]|.zip/, '') rescue '' |     zip_name = response['content-disposition'].split('filename=')[1].gsub(/[\\\"]|.zip/, '') rescue '' | ||||||
|     case purchase._type |     case purchase.class.to_s | ||||||
|       when 'Pdesign' |       when 'Pdesign' | ||||||
|         unzip_design(temp_file, zip_name) |         unzip_design(temp_file, zip_name) | ||||||
|       when 'PModuleApp' |       when 'PModuleApp' | ||||||
|  |  | ||||||
|  | @ -22,7 +22,7 @@ class PagesController < ApplicationController | ||||||
|       @item = Item.first(:conditions => {:path => params[:page_name]}) |       @item = Item.first(:conditions => {:path => params[:page_name]}) | ||||||
|       if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s)) |       if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s)) | ||||||
|         # impressionist(@item) |         # impressionist(@item) | ||||||
|         case @item._type |         case @item.class.to_s | ||||||
|           when 'Page'     |           when 'Page'     | ||||||
|             render_page |             render_page | ||||||
|           when 'Link' |           when 'Link' | ||||||
|  |  | ||||||
|  | @ -30,7 +30,7 @@ class SessionsController < Devise::SessionsController | ||||||
|               render :action => "new" |               render :action => "new" | ||||||
|             else |             else | ||||||
|                logger.info "===ALL passed" |                logger.info "===ALL passed" | ||||||
|               resource_name = resource._type.downcase |               resource_name = resource.class.to_s.downcase | ||||||
|               sign_in(resource_name, resource) |               sign_in(resource_name, resource) | ||||||
|               respond_with resource, :location => redirect_location(resource_name, resource) |               respond_with resource, :location => redirect_location(resource_name, resource) | ||||||
|             end |             end | ||||||
|  | @ -48,7 +48,7 @@ class SessionsController < Devise::SessionsController | ||||||
|           logger.info "=======Rulingcom account======" |           logger.info "=======Rulingcom account======" | ||||||
|           resource = User.first(conditions:{email: login_uid}) |           resource = User.first(conditions:{email: login_uid}) | ||||||
|           if resource.valid_password?(login_password) |           if resource.valid_password?(login_password) | ||||||
|               resource_name = resource._type.downcase |               resource_name = resource.class.to_s.downcase | ||||||
|               sign_in(resource_name, resource) |               sign_in(resource_name, resource) | ||||||
|               respond_with resource, :location => redirect_location(resource_name, resource) |               respond_with resource, :location => redirect_location(resource_name, resource) | ||||||
|             else |             else | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ module Admin::DashboardHelper | ||||||
| 	end | 	end | ||||||
| 
 | 
 | ||||||
| 	def get_link_to_object(object) | 	def get_link_to_object(object) | ||||||
| 		case object._type.underscore | 		case object.class.to_s.underscore | ||||||
| 			when 'bulletin' | 			when 'bulletin' | ||||||
| 				panel_announcement_front_end_bulletin_path(object) | 				panel_announcement_front_end_bulletin_path(object) | ||||||
| 			when 'news_bulletin' | 			when 'news_bulletin' | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ module Admin::ItemHelper | ||||||
|   def render_node_and_children(node) |   def render_node_and_children(node) | ||||||
|     ret = '' |     ret = '' | ||||||
|     if node |     if node | ||||||
|       case node._type |       case node.class.to_s | ||||||
|         when 'Page' |         when 'Page' | ||||||
|           dest = admin_page_path(node) |           dest = admin_page_path(node) | ||||||
|         when 'Link' |         when 'Link' | ||||||
|  | @ -15,10 +15,10 @@ module Admin::ItemHelper | ||||||
|       ret << "<div class='with_action'><i class='icons-moves'></i>" |       ret << "<div class='with_action'><i class='icons-moves'></i>" | ||||||
|       ret << (link_to node.title, dest, :class => 'js_history') |       ret << (link_to node.title, dest, :class => 'js_history') | ||||||
|       ret << "<div class='quick-edit hide'>" |       ret << "<div class='quick-edit hide'>" | ||||||
|       ret << (link_to t('admin.edit'), eval("edit_admin_#{node._type.downcase}_path(node)"), :class => 'js_history') if node._type.eql?('Page') |       ret << (link_to t('admin.edit'), eval("edit_admin_#{node.class.to_s.downcase}_path(node)"), :class => 'js_history') if node.class.to_s.eql?('Page') | ||||||
|       ret << (link_to t('admin.new_page'), new_admin_page_path(:parent_id => node.id), :class => 'new_page js_history') if node._type.eql?('Page') |       ret << (link_to t('admin.new_page'), new_admin_page_path(:parent_id => node.id), :class => 'new_page js_history') if node.class.to_s.eql?('Page') | ||||||
|       ret << (link_to t('admin.new_link'), new_admin_link_path(:parent_id => node.id), :class => 'new_link js_history') if node._type.eql?('Page') |       ret << (link_to t('admin.new_link'), new_admin_link_path(:parent_id => node.id), :class => 'new_link js_history') if node.class.to_s.eql?('Page') | ||||||
|       ret << (link_to t(:delete), eval("delete_admin_#{node._type.downcase}_path(node, :authenticity_token => form_authenticity_token)"), :confirm => t('sure?'), :class => 'delete js_history') |       ret << (link_to t(:delete), eval("delete_admin_#{node.class.to_s.downcase}_path(node, :authenticity_token => form_authenticity_token)"), :confirm => t('sure?'), :class => 'delete js_history') | ||||||
|       ret << "</div>" |       ret << "</div>" | ||||||
|       ret << "</div>" |       ret << "</div>" | ||||||
|       ret << render_children(node) |       ret << render_children(node) | ||||||
|  |  | ||||||
|  | @ -4,7 +4,9 @@ class Tag | ||||||
|   include Impressionist::Impressionable |   include Impressionist::Impressionable | ||||||
|    |    | ||||||
|   is_impressionable :counter_cache => { :column_name => :view_count } |   is_impressionable :counter_cache => { :column_name => :view_count } | ||||||
|  |    | ||||||
|   field :key |   field :key | ||||||
|  |   field :view_count, :type => Integer, :default => 0 | ||||||
|   #field :cloud_amper,:type: Integer,:default=> 0  |   #field :cloud_amper,:type: Integer,:default=> 0  | ||||||
|   belongs_to :module_app |   belongs_to :module_app | ||||||
|    |    | ||||||
|  |  | ||||||
|  | @ -515,7 +515,7 @@ | ||||||
|                                 <% @recent_updated.each do |object| %> |                                 <% @recent_updated.each do |object| %> | ||||||
|                                     <tr> |                                     <tr> | ||||||
|                                         <td><%= link_to ((object[0].title rescue nil) || (object[0].page.title rescue nil)), get_link_to_object(object[0]) %></td> |                                         <td><%= link_to ((object[0].title rescue nil) || (object[0].page.title rescue nil)), get_link_to_object(object[0]) %></td> | ||||||
|                                         <td class="span2"><%= link_to t("dashboard.#{object[0]._type.underscore}"), get_link(object[0]._type.underscore) %></td> |                                         <td class="span2"><%= link_to t("dashboard.#{object[0].class.to_s.underscore}"), get_link(object[0].class.to_s.underscore) %></td> | ||||||
|                                     </tr> |                                     </tr> | ||||||
|                                 <% end %> |                                 <% end %> | ||||||
|                             </tbody> |                             </tbody> | ||||||
|  | @ -553,7 +553,7 @@ | ||||||
|                                 <% @most_visited.each do |object| %> |                                 <% @most_visited.each do |object| %> | ||||||
|                                     <tr> |                                     <tr> | ||||||
|                                         <td><%= link_to ((object[0].title rescue nil) || (object[0].page.title rescue nil)), get_link_to_object(object[0]) %></td> |                                         <td><%= link_to ((object[0].title rescue nil) || (object[0].page.title rescue nil)), get_link_to_object(object[0]) %></td> | ||||||
|                                         <td class="span2"><%= link_to t("dashboard.#{object[0]._type.underscore}"), get_link(object[0]._type.underscore) %></td> |                                         <td class="span2"><%= link_to t("dashboard.#{object[0].class.to_s.underscore}"), get_link(object[0].class.to_s.underscore) %></td> | ||||||
|                                         <td class="span2"><%= object[1] %></td> |                                         <td class="span2"><%= object[1] %></td> | ||||||
|                                     </tr> |                                     </tr> | ||||||
|                                 <% end %> |                                 <% end %> | ||||||
|  |  | ||||||
|  | @ -2,4 +2,4 @@ | ||||||
| 	<%= render 'admin/items/site_map_left_bar' %> | 	<%= render 'admin/items/site_map_left_bar' %> | ||||||
| <% end -%> | <% end -%> | ||||||
| 
 | 
 | ||||||
| <%= render "admin/#{@item._type.downcase.pluralize}/show" %> | <%= render "admin/#{@item.class.to_s.downcase.pluralize}/show" %> | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| $('#back_main').empty(); | $('#back_main').empty(); | ||||||
| <% case @item._type %> | <% case @item.class.to_s %> | ||||||
| 	<% when 'Page' %> | 	<% when 'Page' %> | ||||||
| 		$('#back_main').append("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>"); | 		$('#back_main').append("<%= escape_javascript(render(:partial => 'admin/pages/show')) %>"); | ||||||
| 	<% when 'Link' %> | 	<% when 'Link' %> | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ module ParserBackEnd | ||||||
|       #   item = Item.first(:conditions => { :path => tag.attr['name'] }) |       #   item = Item.first(:conditions => { :path => tag.attr['name'] }) | ||||||
|       #   ret = '' |       #   ret = '' | ||||||
|       #   ret << "<a href='" |       #   ret << "<a href='" | ||||||
|       #   ret << eval("admin_#{item._type.downcase}_path(item.id)") |       #   ret << eval("admin_#{item.class.to_s.downcase}_path(item.id)") | ||||||
|       #   ret << "' class='nav'>" |       #   ret << "' class='nav'>" | ||||||
|       #   ret << item.i18n_variable[I18n.locale] |       #   ret << item.i18n_variable[I18n.locale] | ||||||
|       #   ret << "</a>" |       #   ret << "</a>" | ||||||
|  |  | ||||||
|  | @ -28,7 +28,7 @@ module ParserCommon | ||||||
|     res << " active" if (current_page.id.eql?(page.id) || current_page.descendant_of?(page)) |     res << " active" if (current_page.id.eql?(page.id) || current_page.descendant_of?(page)) | ||||||
|     res << "'>" |     res << "'>" | ||||||
|     root = "/" |     root = "/" | ||||||
|     res << "<a href='#{edit ? root + admin_page_path(page.id) : (page._type.eql?('Page') ? root + page.path : page.url)}'><span>#{page.title}</span></a>" |     res << "<a href='#{edit ? root + admin_page_path(page.id) : (page.class.to_s.eql?('Page') ? root + page.path : page.url)}'><span>#{page.title}</span></a>" | ||||||
|     if page.visible_children.size > 0 && current < menu.levels |     if page.visible_children.size > 0 && current < menu.levels | ||||||
|       res << "<span class='dot'></span>" |       res << "<span class='dot'></span>" | ||||||
|       res << menu_level(page, current_page, current + 1, menu, edit) |       res << menu_level(page, current_page, current + 1, menu, edit) | ||||||
|  | @ -121,7 +121,7 @@ module ParserCommon | ||||||
|         menu_page.visible_children.each do |child| |         menu_page.visible_children.each do |child| | ||||||
|           res << "<li class='#{page.id.eql?(child.id) ? 'active' : nil}'>" |           res << "<li class='#{page.id.eql?(child.id) ? 'active' : nil}'>" | ||||||
|           root = "/" |           root = "/" | ||||||
|           res << "<a href='#{edit ? root + admin_page_path(child.id) : (child._type.eql?('Page') ? root + child.path : child.url)}'>#{child.title}</a>" |           res << "<a href='#{edit ? root + admin_page_path(child.id) : (child.class.to_s.eql?('Page') ? root + child.path : child.url)}'>#{child.title}</a>" | ||||||
|           res << "</li>" |           res << "</li>" | ||||||
|         end |         end | ||||||
|         res << "</ul>" |         res << "</ul>" | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ class Bulletin | ||||||
| 
 | 
 | ||||||
|   #scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false) |   #scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false) | ||||||
| 
 | 
 | ||||||
|   # is_impressionable :counter_cache => { :column_name => :view_count } |   is_impressionable :counter_cache => { :column_name => :view_count } | ||||||
| 
 | 
 | ||||||
|   field :title, localize: true |   field :title, localize: true | ||||||
|   field :subtitle, localize: true |   field :subtitle, localize: true | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ class NewsBulletin | ||||||
| 
 | 
 | ||||||
|   #scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false) |   #scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false) | ||||||
| 
 | 
 | ||||||
|   # is_impressionable :counter_cache => { :column_name => :view_count } |   is_impressionable :counter_cache => { :column_name => :view_count } | ||||||
| 
 | 
 | ||||||
|   field :title, localize: true |   field :title, localize: true | ||||||
|   field :subtitle, localize: true |   field :subtitle, localize: true | ||||||
|  |  | ||||||
|  | @ -1,13 +0,0 @@ | ||||||
| source 'https://rubygems.org' |  | ||||||
| 
 |  | ||||||
| platforms :jruby do |  | ||||||
|   gem 'activerecord-jdbcsqlite3-adapter' |  | ||||||
|   gem 'jdbc-sqlite3' |  | ||||||
|   gem 'jruby-openssl' |  | ||||||
| end |  | ||||||
| 
 |  | ||||||
| platforms :ruby, :mswin, :mingw do |  | ||||||
|   gem 'sqlite3' |  | ||||||
| end |  | ||||||
| 
 |  | ||||||
| gemspec |  | ||||||
|  | @ -1,62 +0,0 @@ | ||||||
| module Impressionist |  | ||||||
|   module Impressionable |  | ||||||
|     extend ActiveSupport::Concern |  | ||||||
| 
 |  | ||||||
|     module ClassMethods |  | ||||||
|       attr_accessor :impressionist_cache_options |  | ||||||
|       @impressionist_cache_options = nil |  | ||||||
| 
 |  | ||||||
|       def impressionist_counter_cache_options |  | ||||||
|         if @impressionist_cache_options |  | ||||||
|           options = { :column_name => :impressions_count, :unique => false } |  | ||||||
|           options.merge!(@impressionist_cache_options) if @impressionist_cache_options.is_a?(Hash) |  | ||||||
|           options |  | ||||||
|         end |  | ||||||
|       end |  | ||||||
| 
 |  | ||||||
|       def impressionist_counter_caching? |  | ||||||
|         impressionist_counter_cache_options.present? |  | ||||||
|       end |  | ||||||
| 
 |  | ||||||
|       def counter_caching? |  | ||||||
|         ::ActiveSupport::Deprecation.warn("#counter_caching? is deprecated; please use #impressionist_counter_caching? instead") |  | ||||||
|         impressionist_counter_caching? |  | ||||||
|       end |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     def impressionable? |  | ||||||
|       true |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     def impressionist_count(options={}) |  | ||||||
|       options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now) |  | ||||||
|       imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and created_at<=?",options[:start_date],options[:end_date]) |  | ||||||
|       options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true) |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     def update_impressionist_counter_cache |  | ||||||
|       cache_options = self.class.impressionist_counter_cache_options |  | ||||||
|       column_name = cache_options[:column_name].to_sym |  | ||||||
|       count = cache_options[:unique] ? impressionist_count(:filter => :ip_address) : impressionist_count |  | ||||||
|       old_count = send(column_name) || 0 |  | ||||||
|       self.class.update_counters(id, column_name => (count - old_count)) |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     # OLD METHODS - DEPRECATE IN V0.5 |  | ||||||
|     def impression_count(start_date=nil,end_date=Time.now) |  | ||||||
|       impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=>:all}) |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     def unique_impression_count(start_date=nil,end_date=Time.now) |  | ||||||
|       impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :request_hash}) |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     def unique_impression_count_ip(start_date=nil,end_date=Time.now) |  | ||||||
|       impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :ip_address}) |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     def unique_impression_count_session(start_date=nil,end_date=Time.now) |  | ||||||
|       impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :session_hash}) |  | ||||||
|     end |  | ||||||
|   end |  | ||||||
| end |  | ||||||
|  | @ -1,13 +0,0 @@ | ||||||
| module Impressionist |  | ||||||
|   module Generators |  | ||||||
|     class ImpressionistGenerator < Rails::Generators::Base |  | ||||||
|       hook_for :orm |  | ||||||
|       source_root File.expand_path('../templates', __FILE__) |  | ||||||
| 
 |  | ||||||
|       def copy_config_file |  | ||||||
|         template 'impression.rb', 'config/initializers/impression.rb' |  | ||||||
|       end |  | ||||||
| 
 |  | ||||||
|     end |  | ||||||
|   end |  | ||||||
| end |  | ||||||
|  | @ -1,5 +0,0 @@ | ||||||
| # Use this hook to configure impressionist parameters |  | ||||||
| Impressionist.setup do |config| |  | ||||||
|   # Define ORM. Could be :active_record (default), :mongo_mapper or :mongoid |  | ||||||
|   # config.orm = :active_record |  | ||||||
| end |  | ||||||
|  | @ -1,10 +0,0 @@ | ||||||
| ImpressionistController::InstanceMethods.send(:define_method, :direct_create_statement) do |query_params={}| |  | ||||||
| 	# creates a statment hash that contains default values for creating an impression. |  | ||||||
| 	# if :impressionable_id is a valid ObjectId then convert it into one |  | ||||||
| 	base = (defined? Moped) ? Moped::BSON : BSON |  | ||||||
| 	query_params.reverse_merge!( |  | ||||||
| 		:impressionable_type => controller_name.singularize.camelize, |  | ||||||
| 		:impressionable_id=> !base::ObjectId.legal?(params[:id]) ? params[:id] : base::ObjectId.from_string(params[:id]) |  | ||||||
| 	) |  | ||||||
| 	associative_create_statement(query_params) |  | ||||||
| end |  | ||||||
|  | @ -1,33 +0,0 @@ | ||||||
| require "impressionist" |  | ||||||
| require "rails" |  | ||||||
| 
 |  | ||||||
| module Impressionist |  | ||||||
|   class Engine < Rails::Engine |  | ||||||
|     initializer 'impressionist.model' do |app| |  | ||||||
|       require "#{root}/app/models/impressionist/impressionable.rb" |  | ||||||
|       if Impressionist.orm == :active_record && defined? ActiveRecord |  | ||||||
|         require "impressionist/models/active_record/impression.rb" |  | ||||||
|         require "impressionist/models/active_record/impressionist/impressionable.rb" |  | ||||||
|         ActiveRecord::Base.send(:include, Impressionist::Impressionable) |  | ||||||
|       elsif Impressionist.orm == :mongo_mapper |  | ||||||
|         require "impressionist/models/mongo_mapper/impression.rb" |  | ||||||
|         require "impressionist/models/mongo_mapper/impressionist/impressionable.rb" |  | ||||||
|         MongoMapper::Document.plugin Impressionist::Impressionable |  | ||||||
|       elsif Impressionist.orm == :mongoid |  | ||||||
|         require 'impressionist/models/mongoid/impression.rb' |  | ||||||
|         require 'impressionist/models/mongoid/impressionist/impressionable.rb' |  | ||||||
|         Mongoid::Document.send(:include, Impressionist::Impressionable) |  | ||||||
|       end |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     initializer 'impressionist.controller' do |  | ||||||
|       if Impressionist.orm == :mongoid |  | ||||||
|           require 'impressionist/controllers/mongoid/impressionist_controller.rb' |  | ||||||
|       end |  | ||||||
|       ActiveSupport.on_load(:action_controller) do |  | ||||||
|         include ImpressionistController::InstanceMethods |  | ||||||
|         extend ImpressionistController::ClassMethods |  | ||||||
|       end |  | ||||||
|     end |  | ||||||
|   end |  | ||||||
| end |  | ||||||
|  | @ -1,32 +0,0 @@ | ||||||
| class Impression |  | ||||||
|   include Mongoid::Document |  | ||||||
|   include Mongoid::Timestamps |  | ||||||
| 
 |  | ||||||
|   attr_accessible :impressionable_type, :impressionable_field, :impressionable_id, :user_id, |  | ||||||
|   :controller_name, :action_name, :view_name, :request_hash, :ip_address, |  | ||||||
|   :session_hash, :message, :referrer |  | ||||||
| 
 |  | ||||||
|   belongs_to :impressionable, polymorphic: true |  | ||||||
| 
 |  | ||||||
|   field :user_id |  | ||||||
|   field :controller_name |  | ||||||
|   field :action_name |  | ||||||
|   field :view_name |  | ||||||
|   field :request_hash |  | ||||||
|   field :ip_address |  | ||||||
|   field :session_hash |  | ||||||
|   field :message |  | ||||||
|   field :referrer |  | ||||||
| 
 |  | ||||||
|   set_callback(:create, :after) do |doc| |  | ||||||
|     unless impressionable_id.nil? |  | ||||||
|       impressionable_class = doc.impressionable_type.constantize |  | ||||||
| 
 |  | ||||||
|       if impressionable_class.impressionist_counter_cache_options |  | ||||||
|         resource = impressionable_class.find(doc.impressionable_id) |  | ||||||
|         resource.try(:update_impressionist_counter_cache) |  | ||||||
|       end |  | ||||||
|     end |  | ||||||
|   end |  | ||||||
|    |  | ||||||
| end |  | ||||||
|  | @ -1,52 +0,0 @@ | ||||||
| module Impressionist |  | ||||||
|   module Impressionable |  | ||||||
|     extend ActiveSupport::Concern |  | ||||||
| 
 |  | ||||||
|     module ClassMethods |  | ||||||
|       def is_impressionable(options={}) |  | ||||||
|       	has_many :impressions, as: :impressionable, dependent: :destroy |  | ||||||
|         	@impressionist_cache_options = options[:counter_cache] |  | ||||||
|         	if !@impressionist_cache_options.nil? |  | ||||||
|         		opts = impressionist_counter_cache_options |  | ||||||
|         		field opts[:column_name], type: Integer |  | ||||||
|         	end |  | ||||||
|       end |  | ||||||
| 
 |  | ||||||
|       def impressionist_counter_cache_options |  | ||||||
|         if @impressionist_cache_options |  | ||||||
|           options = { :column_name => :impressions_count, :unique => false } |  | ||||||
|           options.merge!(@impressionist_cache_options) if @impressionist_cache_options.is_a?(Hash) |  | ||||||
|           options |  | ||||||
|         end |  | ||||||
|       end |  | ||||||
| 
 |  | ||||||
|       def impressionist_counter_caching? |  | ||||||
|         impressionist_counter_cache_options.present? |  | ||||||
|       end |  | ||||||
| 
 |  | ||||||
|       def counter_caching? |  | ||||||
|         ::ActiveSupport::Deprecation.warn("#counter_caching? is deprecated; please use #impressionist_counter_caching? instead") |  | ||||||
|         impressionist_counter_caching? |  | ||||||
|       end |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     def impressionable? |  | ||||||
|       true |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     def impressionist_count(options={}) |  | ||||||
|       options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now) |  | ||||||
|       imps = options[:start_date].blank? ? impressions : impressions.between(created_at: options[:start_date]..options[:end_date]) |  | ||||||
|       options[:filter] == :all ? imps.count : imps.where(options[:filter].ne => nil).count |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     def update_impressionist_counter_cache |  | ||||||
|       cache_options = self.class.impressionist_counter_cache_options |  | ||||||
|       column_name = cache_options[:column_name].to_sym |  | ||||||
|       count = cache_options[:unique] ? impressionist_count(:filter => :ip_address) : impressionist_count |  | ||||||
|       old_count = send(column_name) || 0 |  | ||||||
|       self.inc(column_name, (count - old_count)) |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|   end |  | ||||||
| end |  | ||||||
|  | @ -1,50 +0,0 @@ | ||||||
| require 'spec_helper' |  | ||||||
| 
 |  | ||||||
| describe Impression do |  | ||||||
|   fixtures :widgets |  | ||||||
| 
 |  | ||||||
|   before(:each) do |  | ||||||
|     @widget = Widget.find(1) |  | ||||||
|     Impression.destroy_all |  | ||||||
|   end |  | ||||||
| 
 |  | ||||||
|   describe "self#impressionist_counter_caching?" do |  | ||||||
|     it "should know when counter caching is enabled" do |  | ||||||
|       Widget.should be_impressionist_counter_caching |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     it "should know when counter caching is disabled" do |  | ||||||
|       Article.should_not be_impressionist_counter_caching |  | ||||||
|     end |  | ||||||
|   end |  | ||||||
| 
 |  | ||||||
|   describe "self#counter_caching?" do |  | ||||||
|     it "should know when counter caching is enabled" do |  | ||||||
|       ActiveSupport::Deprecation.should_receive(:warn) |  | ||||||
|       Widget.should be_counter_caching |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     it "should know when counter caching is disabled" do |  | ||||||
|       ActiveSupport::Deprecation.should_receive(:warn) |  | ||||||
|       Article.should_not be_counter_caching |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|   end |  | ||||||
| 
 |  | ||||||
|   describe "#update_impressionist_counter_cache" do |  | ||||||
|     it "should update the counter cache column to reflect the correct number of impressions" do |  | ||||||
|       lambda { |  | ||||||
|          @widget.impressions.create(:request_hash => 'abcd1234') |  | ||||||
|          @widget.reload |  | ||||||
|        }.should change(@widget, :impressions_count).from(0).to(1) |  | ||||||
|     end |  | ||||||
| 
 |  | ||||||
|     it "should not update the timestamp on the impressable" do |  | ||||||
|       lambda { |  | ||||||
|          @widget.impressions.create(:request_hash => 'abcd1234') |  | ||||||
|          @widget.reload |  | ||||||
|        }.should_not change(@widget, :updated_at) |  | ||||||
|     end |  | ||||||
|   end |  | ||||||
| 
 |  | ||||||
| end |  | ||||||
		Loading…
	
		Reference in New Issue