diff --git a/Gemfile b/Gemfile index a648f6f..7a57726 100644 --- a/Gemfile +++ b/Gemfile @@ -1,23 +1,11 @@ source :rubygems -gem 'cucumber', '0.4.0' -gem 'webrat', '0.5.1' -gem 'rspec', '1.2.9' -gem 'rspec-rails', '1.2.9' -gem 'Selenium', '>= 1.1.14' -gem 'selenium-client', '>= 1.2.17' -gem 'database_cleaner' -gem 'exception_notification', '~> 3.0.0' - -#Forcing to use Debian version of this gems -#Without this, exception_notification uses 3.1.3 -gem 'actionmailer', '3.2.6' -gem 'actionpack', '3.2.6' -gem 'activemodel', '3.2.6' -gem 'activerecord', '3.2.6' -gem 'activeresource', '3.2.6' -gem 'activesupport', '3.2.6' +gem 'cucumber' +# TODO needs a rebuild diff-lcs wrt wheezy +gem 'rspec' +# gem 'rspec-rails', '1.2.9' # FIXME package this +gem 'rails' def program(name) unless system("which #{name} > /dev/null") diff --git a/Gemfile.lock b/Gemfile.lock index 44b1b61..f6d932c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,6 @@ GEM remote: http://rubygems.org/ specs: - Selenium (1.1.14) actionmailer (3.2.6) actionpack (= 3.2.6) mail (~> 2.4.4) @@ -30,94 +29,75 @@ GEM i18n (~> 0.6) multi_json (~> 1.0) arel (3.0.2) - builder (3.0.4) - cucumber (0.4.0) + builder (3.0.0) + cucumber (1.2.1) builder (>= 2.1.2) - diff-lcs (>= 1.1.2) - polyglot (>= 0.2.9) - term-ansicolor (>= 1.0.3) - treetop (>= 1.4.2) - database_cleaner (0.7.0) + diff-lcs (>= 1.1.3) + gherkin (~> 2.11.0) + json (>= 1.4.6) diff-lcs (1.1.3) erubis (2.7.0) - eventmachine (1.0.0) - exception_notification (3.0.0) - actionmailer (>= 3.0.4) - tinder (~> 1.8) - faraday (0.8.4) - multipart-post (~> 1.1) - faraday_middleware (0.9.0) - faraday (>= 0.7.4, < 0.9) - hashie (1.2.0) + gherkin (2.11.1) + json (>= 1.4.6) hike (1.2.1) - http_parser.rb (0.5.3) - i18n (0.6.1) - journey (1.0.4) - json (1.7.5) + i18n (0.6.0) + journey (1.0.3) + json (1.7.3) mail (2.4.4) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.19) - multi_json (1.3.7) - multipart-post (1.1.5) - nokogiri (1.5.5) + multi_json (1.3.6) polyglot (0.3.3) rack (1.4.1) rack-cache (1.2) rack (>= 0.4) + rack-ssl (1.3.2) + rack rack-test (0.6.2) rack (>= 1.0) - rspec (1.2.9) - rspec-rails (1.2.9) - rack (>= 1.0.0) - rspec (>= 1.2.9) - selenium-client (1.2.18) - simple_oauth (0.1.9) + rails (3.2.6) + actionmailer (= 3.2.6) + actionpack (= 3.2.6) + activerecord (= 3.2.6) + activeresource (= 3.2.6) + activesupport (= 3.2.6) + bundler (~> 1.0) + railties (= 3.2.6) + railties (3.2.6) + actionpack (= 3.2.6) + activesupport (= 3.2.6) + rack-ssl (~> 1.3.2) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (>= 0.14.6, < 2.0) + rake (0.9.2.2) + rdoc (3.9.4) + rspec (2.10.0) + rspec-core (~> 2.10.0) + rspec-expectations (~> 2.10.0) + rspec-mocks (~> 2.10.0) + rspec-core (2.10.1) + rspec-expectations (2.10.0) + diff-lcs (~> 1.1.3) + rspec-mocks (2.10.1) sprockets (2.1.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - term-ansicolor (1.0.7) + thor (0.15.3) tilt (1.3.3) - tinder (1.9.1) - eventmachine (>= 0.12.0, < 2) - faraday (~> 0.8) - faraday_middleware (~> 0.8) - hashie (~> 1.0) - json (~> 1.6) - mime-types (~> 1.16) - multi_json (~> 1.0) - multipart-post (~> 1.1) - twitter-stream (~> 0.1) - treetop (1.4.12) + treetop (1.4.10) polyglot polyglot (>= 0.3.1) - twitter-stream (0.1.16) - eventmachine (>= 0.12.8) - http_parser.rb (~> 0.5.1) - simple_oauth (~> 0.1.4) - tzinfo (0.3.35) - webrat (0.5.1) - nokogiri (>= 1.2.0) - rack (>= 1.0) + tzinfo (0.3.33) PLATFORMS ruby DEPENDENCIES - Selenium (>= 1.1.14) - actionmailer (= 3.2.6) - actionpack (= 3.2.6) - activemodel (= 3.2.6) - activerecord (= 3.2.6) - activeresource (= 3.2.6) - activesupport (= 3.2.6) - cucumber (= 0.4.0) - database_cleaner - exception_notification (~> 3.0.0) - rspec (= 1.2.9) - rspec-rails (= 1.2.9) - selenium-client (>= 1.2.17) - webrat (= 0.5.1) + cucumber + rails + rspec diff --git a/Rakefile b/Rakefile index 6d7ea85..c31aadc 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,8 @@ +#!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require(File.join(File.dirname(__FILE__), 'config', 'boot')) +require File.expand_path('../config/application', __FILE__) -require 'rake' -require 'rake/testtask' -require 'rake/rdoctask' +Noosfero::Application.load_tasks -ACTS_AS_SEARCHABLE_ENABLED = false if Rake.application.top_level_tasks.detect{|t| t == 'db:data:minimal'} - -require 'tasks/rails' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 60e94b3..d72b0e5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,7 @@ +require 'noosfero/multi_tenancy' + class ApplicationController < ActionController::Base - protec_from_forgery + protect_from_forgery before_filter :setup_multitenancy before_filter :detect_stuff_by_domain @@ -12,11 +14,9 @@ class ApplicationController < ActionController::Base theme_option(:layout) || 'application' end - filter_parameter_logging :password - def log_processing super - return unless ENV['RAILS_ENV'] == 'production' + return unless Rails.env == 'production' if logger && logger.info? logger.info(" HTTP Referer: #{request.referer}") logger.info(" User Agent: #{request.user_agent}") @@ -94,7 +94,10 @@ class ApplicationController < ActionController::Base @environment = Environment.default if @environment.nil? && Rails.env.development? # This should only happen in development ... - @environment = Environment.create!(:name => "Noosfero", :is_default => true) + @environment = Environment.new + @environment.name = "Noosfero" + @environment.is_default = true + @environment.save! end else @environment = @domain.environment diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ef0670b..fdcec12 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,5 @@ +# encoding: UTF-8 + require 'redcloth' # Methods added to this helper will be available to all templates in the @@ -365,10 +367,10 @@ module ApplicationHelper # utility for developers: set the theme to 'random' in development mode and # you will get a different theme every request. This is interesting for # testing - if ENV['RAILS_ENV'] == 'development' && environment.theme == 'random' + if Rails.env == 'development' && environment.theme == 'random' @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand @random_theme - elsif ENV['RAILS_ENV'] == 'development' && params[:theme] && File.exists?(File.join(Rails.root, 'public/designs/themes', params[:theme])) + elsif Rails.env == 'development' && params[:theme] && File.exists?(File.join(Rails.root, 'public/designs/themes', params[:theme])) params[:theme] else if profile && !profile.theme.nil? diff --git a/app/helpers/countries_helper.rb b/app/helpers/countries_helper.rb index 944c519..461824a 100644 --- a/app/helpers/countries_helper.rb +++ b/app/helpers/countries_helper.rb @@ -1,6 +1,11 @@ -class CountriesHelper +# encoding: UTF-8 - include Singleton +module CountriesHelper + + class Object + include ::CountriesHelper + include Singleton + end # a dump of iso_3166.xml from Debian source package iso-codes COUNTRIES = [ diff --git a/app/helpers/folder_helper.rb b/app/helpers/folder_helper.rb index 7dd4dff..de67f9d 100644 --- a/app/helpers/folder_helper.rb +++ b/app/helpers/folder_helper.rb @@ -1,3 +1,5 @@ +require 'short_filename' + module FolderHelper include ShortFilename diff --git a/app/helpers/manage_products_helper.rb b/app/helpers/manage_products_helper.rb index 2c4ee06..1bc51d2 100644 --- a/app/helpers/manage_products_helper.rb +++ b/app/helpers/manage_products_helper.rb @@ -1,3 +1,5 @@ +# encoding: UTF-8 + module ManageProductsHelper def remote_function_to_update_categories_selection(container_id, options = {}) diff --git a/app/helpers/profile_editor_helper.rb b/app/helpers/profile_editor_helper.rb index 7cb999e..08d0a5c 100644 --- a/app/helpers/profile_editor_helper.rb +++ b/app/helpers/profile_editor_helper.rb @@ -101,7 +101,7 @@ module ProfileEditorHelper end def country_helper - @country_helper ||= CountriesHelper.instance + @country_helper ||= CountriesHelper::Object.instance end def select_country(title, object, method, html_options = {}, options = {}) diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index a0096e3..fb4d082 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -1,3 +1,5 @@ +# encoding: UTF-8 + module TagsHelper module Cloud diff --git a/app/models/article.rb b/app/models/article.rb index 033af35..2688811 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -67,11 +67,11 @@ class Article < ActiveRecord::Base xss_terminate :only => [ :name ], :on => 'validation', :with => 'white_list' - named_scope :in_category, lambda { |category| + scope :in_category, lambda { |category| {:include => 'categories_including_virtual', :conditions => { 'categories.id' => category.id }} } - named_scope :by_range, lambda { |range| { + scope :by_range, lambda { |range| { :conditions => [ 'published_at BETWEEN :start_date AND :end_date', { :start_date => range.first, :end_date => range.last } ] @@ -187,16 +187,16 @@ class Article < ActiveRecord::Base # retrieves all articles belonging to the given +profile+ that are not # sub-articles of any other article. - named_scope :top_level_for, lambda { |profile| + scope :top_level_for, lambda { |profile| {:conditions => [ 'parent_id is null and profile_id = ?', profile.id ]} } - named_scope :join_profile, :joins => [:profile] + scope :join_profile, :joins => [:profile] - named_scope :public, + scope :public, :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ?", true, true, true, true ] - named_scope :more_recent, + scope :more_recent, :conditions => [ "advertise = ? AND published = ? AND profiles.visible = ? AND profiles.public_profile = ? AND ((articles.type != ?) OR articles.type is NULL)", true, true, true, true, 'RssFeed' @@ -209,8 +209,8 @@ class Article < ActiveRecord::Base paginate(:order => 'comments_count DESC', :page => 1, :per_page => limit) end - named_scope :more_popular, :order => 'hits DESC' - named_scope :relevant_as_recent, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"] + scope :more_popular, :order => 'hits DESC' + scope :relevant_as_recent, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'RssFeed' and articles.type != 'Blog') OR articles.type is NULL"] def self.recent(limit = nil, extra_conditions = {}, pagination = true) result = scoped({:conditions => extra_conditions}). @@ -331,7 +331,7 @@ class Article < ActiveRecord::Base false end - named_scope :native_translations, :conditions => { :translation_of_id => nil } + scope :native_translations, :conditions => { :translation_of_id => nil } def translatable? false @@ -409,16 +409,16 @@ class Article < ActiveRecord::Base ['TextArticle', 'TextileArticle', 'TinyMceArticle'] end - named_scope :published, :conditions => { :published => true } - named_scope :folders, :conditions => { :type => folder_types} - named_scope :no_folders, :conditions => ['type NOT IN (?)', folder_types] - named_scope :galleries, :conditions => { :type => 'Gallery' } - named_scope :images, :conditions => { :is_image => true } - named_scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] + scope :published, :conditions => { :published => true } + scope :folders, :conditions => { :type => folder_types} + scope :no_folders, :conditions => ['type NOT IN (?)', folder_types] + scope :galleries, :conditions => { :type => 'Gallery' } + scope :images, :conditions => { :is_image => true } + scope :text_articles, :conditions => [ 'articles.type IN (?)', text_article_types ] - named_scope :more_comments, :order => "comments_count DESC" - named_scope :more_views, :order => "hits DESC" - named_scope :more_recent, :order => "created_at DESC" + scope :more_comments, :order => "comments_count DESC" + scope :more_views, :order => "hits DESC" + scope :more_recent, :order => "created_at DESC" def self.display_filter(user, profile) return {:conditions => ['published = ?', true]} if !user diff --git a/app/models/block.rb b/app/models/block.rb index 9fab33b..bce8427 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -14,7 +14,7 @@ class Block < ActiveRecord::Base acts_as_having_settings - named_scope :enabled, :conditions => { :enabled => true } + scope :enabled, :conditions => { :enabled => true } # Determines whether a given block must be visible. Optionally a # context must be specified. context must be a hash, and diff --git a/app/models/category.rb b/app/models/category.rb index 874f560..0b7909d 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -9,7 +9,7 @@ class Category < ActiveRecord::Base validates_uniqueness_of :display_color, :scope => :environment_id, :if => (lambda { |cat| ! cat.display_color.nil? }), :message => N_('%{fn} was already assigned to another category.').fix_i18n # Finds all top level categories for a given environment. - named_scope :top_level_for, lambda { |environment| + scope :top_level_for, lambda { |environment| {:conditions => ['parent_id is null and environment_id = ?', environment.id ]} } @@ -31,7 +31,7 @@ class Category < ActiveRecord::Base acts_as_having_image - named_scope :from_types, lambda { |types| + scope :from_types, lambda { |types| types.select{ |t| t.blank? }.empty? ? { :conditions => { :type => types } } : { :conditions => [ "type IN (?) OR type IS NULL", types.reject{ |t| t.blank? } ] } diff --git a/app/models/change_password.rb b/app/models/change_password.rb index d77e02d..4785f52 100644 --- a/app/models/change_password.rb +++ b/app/models/change_password.rb @@ -37,7 +37,7 @@ class ChangePassword < Task end end - before_validation_on_create do |change_password| + before_validation(:on => :create) do |change_password| change_password.requestor = Person.find_by_identifier_and_environment_id(change_password.login, change_password.environment_id) end diff --git a/app/models/comment.rb b/app/models/comment.rb index 21d11ac..42b80d3 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -10,8 +10,8 @@ class Comment < ActiveRecord::Base has_many :children, :class_name => 'Comment', :foreign_key => 'reply_of_id', :dependent => :destroy belongs_to :reply_of, :class_name => 'Comment', :foreign_key => 'reply_of_id' - named_scope :without_spam, :conditions => ['spam IS NULL OR spam = ?', false] - named_scope :spam, :conditions => ['spam = ?', true] + scope :without_spam, :conditions => ['spam IS NULL OR spam = ?', false] + scope :spam, :conditions => ['spam = ?', true] # unauthenticated authors: validates_presence_of :name, :if => (lambda { |record| !record.email.blank? }) diff --git a/app/models/domain.rb b/app/models/domain.rb index 9b89c61..00c113c 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -1,5 +1,7 @@ class Domain < ActiveRecord::Base + attr_accessible :name + # relationships ############### diff --git a/app/models/environment.rb b/app/models/environment.rb index 9e36191..b2df1c1 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -3,6 +3,8 @@ # domains. class Environment < ActiveRecord::Base + attr_accessible :name, :is_default + has_many :users self.partial_updates = false @@ -586,7 +588,10 @@ class Environment < ActiveRecord::Base validates_numericality_of :reports_lower_bound, :allow_nil => false, :only_integer => true, :greater_than_or_equal_to => 0 include WhiteListFilter - filter_iframes :message_for_disabled_enterprise, :whitelist => lambda { trusted_sites_for_iframe } + filter_iframes :message_for_disabled_enterprise + def iframe_whitelist + trusted_sites_for_iframe + end # ################################################# # Business logic in general diff --git a/app/models/event.rb b/app/models/event.rb index a2f24e4..5732c0d 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -30,12 +30,15 @@ class Event < Article end end - named_scope :by_day, lambda { |date| + scope :by_day, lambda { |date| {:conditions => ['start_date = :date AND end_date IS NULL OR (start_date <= :date AND end_date >= :date)', {:date => date}]} } include WhiteListFilter - filter_iframes :body, :link, :address, :whitelist => lambda { profile && profile.environment && profile.environment.trusted_sites_for_iframe } + filter_iframes :body, :link, :address + def iframe_whitelist + profile && profile.environment && profile.environment.trusted_sites_for_iframe + end def self.description _('A calendar event.') @@ -49,7 +52,7 @@ class Event < Article 'event' end - named_scope :by_range, lambda { |range| { + scope :by_range, lambda { |range| { :conditions => [ 'start_date BETWEEN :start_day AND :end_day OR end_date BETWEEN :start_day AND :end_day', { :start_day => range.first, :end_day => range.last } @@ -79,7 +82,6 @@ class Event < Article # FIXME this shouldn't be needed include ActionView::Helpers::TagHelper include ActionView::Helpers::UrlHelper - include ActionController::UrlWriter include DatesHelper def to_html(options = {}) diff --git a/app/models/external_feed.rb b/app/models/external_feed.rb index 15ead62..40874c5 100644 --- a/app/models/external_feed.rb +++ b/app/models/external_feed.rb @@ -5,8 +5,8 @@ class ExternalFeed < ActiveRecord::Base validates_presence_of :address, :if => lambda {|efeed| efeed.enabled} validates_uniqueness_of :blog_id - named_scope :enabled, :conditions => { :enabled => true } - named_scope :expired, lambda { + scope :enabled, :conditions => { :enabled => true } + scope :expired, lambda { { :conditions => ['(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval] } } diff --git a/app/models/feed_reader_block.rb b/app/models/feed_reader_block.rb index 3ab06ff..1092131 100644 --- a/app/models/feed_reader_block.rb +++ b/app/models/feed_reader_block.rb @@ -24,7 +24,7 @@ class FeedReaderBlock < Block settings_items :update_errors, :type => :integer, :default => 0 settings_items :error_message, :type => :string - named_scope :expired, lambda { + scope :expired, lambda { { :conditions => [ '(fetched_at is NULL) OR (fetched_at < ?)', Time.now - FeedUpdater.update_interval] } } diff --git a/app/models/folder.rb b/app/models/folder.rb index 2a1b0e2..c3b8d9f 100644 --- a/app/models/folder.rb +++ b/app/models/folder.rb @@ -15,7 +15,10 @@ class Folder < Article xss_terminate :only => [ :body ], :with => 'white_list', :on => 'validation' include WhiteListFilter - filter_iframes :body, :whitelist => lambda { profile && profile.environment && profile.environment.trusted_sites_for_iframe } + filter_iframes :body + def iframe_whitelist + profile && profile.environment && profile.environment.trusted_sites_for_iframe + end def self.short_description _('Folder') diff --git a/app/models/input.rb b/app/models/input.rb index b0176b5..242d2e6 100644 --- a/app/models/input.rb +++ b/app/models/input.rb @@ -9,7 +9,7 @@ class Input < ActiveRecord::Base belongs_to :unit - named_scope :relevant_to_price, :conditions => { :relevant_to_price => true } + scope :relevant_to_price, :conditions => { :relevant_to_price => true } include FloatHelper diff --git a/app/models/organization.rb b/app/models/organization.rb index 22e9b81..5a87b34 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -21,13 +21,13 @@ class Organization < Profile has_many :mailings, :class_name => 'OrganizationMailing', :foreign_key => :source_id, :as => 'source' - named_scope :more_popular, + scope :more_popular, :select => "#{Profile.qualified_column_names}, count(resource_id) as total", :group => Profile.qualified_column_names, :joins => "LEFT OUTER JOIN role_assignments ON profiles.id = role_assignments.resource_id", :order => "total DESC" - named_scope :more_active, + scope :more_active, :select => "#{Profile.qualified_column_names}, count(action_tracker.id) as total", :joins => "LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.target_id", :group => Profile.qualified_column_names, diff --git a/app/models/person.rb b/app/models/person.rb index 0df0e32..e7ca0bf 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -22,7 +22,7 @@ class Person < Profile super end - named_scope :members_of, lambda { |resources| + scope :members_of, lambda { |resources| resources = [resources] if !resources.kind_of?(Array) conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => [conditions] } @@ -44,7 +44,7 @@ class Person < Profile has_many :friendships, :dependent => :destroy has_many :friends, :class_name => 'Person', :through => :friendships - named_scope :online, lambda { { :include => :user, :conditions => ["users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes] } } + scope :online, lambda { { :include => :user, :conditions => ["users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes] } } has_many :requested_tasks, :class_name => 'Task', :foreign_key => :requestor_id, :dependent => :destroy @@ -54,21 +54,21 @@ class Person < Profile has_many :scraps_sent, :class_name => 'Scrap', :foreign_key => :sender_id, :dependent => :destroy - named_scope :more_popular, + scope :more_popular, :select => "#{Profile.qualified_column_names}, count(friend_id) as total", :group => Profile.qualified_column_names, :joins => "LEFT OUTER JOIN friendships on profiles.id = friendships.person_id", :order => "total DESC" - named_scope :more_active, + scope :more_active, :select => "#{Profile.qualified_column_names}, count(action_tracker.id) as total", :joins => "LEFT OUTER JOIN action_tracker ON profiles.id = action_tracker.user_id", :group => Profile.qualified_column_names, :order => 'total DESC', :conditions => ['action_tracker.created_at >= ? OR action_tracker.id IS NULL', ActionTracker::Record::RECENT_DELAY.days.ago] - named_scope :abusers, :joins => :abuse_complaints, :conditions => ['tasks.status = 3'], :select => 'DISTINCT profiles.*' - named_scope :non_abusers, :joins => "LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'", :conditions => ["tasks.status != 3 OR tasks.id is NULL"], :select => "DISTINCT profiles.*" + scope :abusers, :joins => :abuse_complaints, :conditions => ['tasks.status = 3'], :select => 'DISTINCT profiles.*' + scope :non_abusers, :joins => "LEFT JOIN tasks ON profiles.id = tasks.requestor_id AND tasks.type='AbuseComplaint'", :conditions => ["tasks.status != 3 OR tasks.id is NULL"], :select => "DISTINCT profiles.*" after_destroy do |person| Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } diff --git a/app/models/product.rb b/app/models/product.rb index 8d910e7..59f3a9f 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -21,7 +21,7 @@ class Product < ActiveRecord::Base validates_numericality_of :price, :allow_nil => true validates_numericality_of :discount, :allow_nil => true - named_scope :more_recent, :order => "created_at DESC" + scope :more_recent, :order => "created_at DESC" after_update :save_image @@ -40,7 +40,11 @@ class Product < ActiveRecord::Base include FloatHelper include WhiteListFilter - filter_iframes :description, :whitelist => lambda { enterprise && enterprise.environment && enterprise.environment.trusted_sites_for_iframe } + filter_iframes :description + + def iframe_whitelist + enterprise && enterprise.environment && enterprise.environment.trusted_sites_for_iframe + end def name self[:name].blank? ? category_name : self[:name] diff --git a/app/models/profile.rb b/app/models/profile.rb index 466391d..6f4358f 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -64,11 +64,11 @@ class Profile < ActiveRecord::Base include Noosfero::Plugin::HotSpot - named_scope :memberships_of, lambda { |person| { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ['role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id ] } } + scope :memberships_of, lambda { |person| { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ['role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id ] } } #FIXME: these will work only if the subclass is already loaded - named_scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } - named_scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } - named_scope :templates, :conditions => {:is_template => true} + scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } + scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } + scope :templates, :conditions => {:is_template => true} def members scopes = plugins.dispatch_scopes(:organization_members, self) @@ -101,12 +101,12 @@ class Profile < ActiveRecord::Base Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') end - named_scope :visible, :conditions => { :visible => true } + scope :visible, :conditions => { :visible => true } # Subclasses must override these methods - named_scope :more_popular - named_scope :more_active + scope :more_popular + scope :more_active - named_scope :more_recent, :order => "created_at DESC" + scope :more_recent, :order => "created_at DESC" acts_as_trackable :dependent => :destroy @@ -127,7 +127,7 @@ class Profile < ActiveRecord::Base scrap.nil? ? Scrap.all_scraps(self) : Scrap.all_scraps(self).find(scrap) end - class_inheritable_accessor :extra_index_methods + class_attribute :extra_index_methods self.extra_index_methods = [] def extra_data_for_index @@ -379,8 +379,10 @@ class Profile < ActiveRecord::Base xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list', :on => 'validation' include WhiteListFilter - filter_iframes :custom_header, :custom_footer, :whitelist => lambda { environment && environment.trusted_sites_for_iframe } - + filter_iframes :custom_header, :custom_footer + def iframe_whitelist + environment && environment.trusted_sites_for_iframe + end # returns the contact email for this profile. # diff --git a/app/models/region.rb b/app/models/region.rb index cd9a64b..a96c2b6 100644 --- a/app/models/region.rb +++ b/app/models/region.rb @@ -14,7 +14,7 @@ class Region < Category validators.count > 0 end - named_scope :with_validators, :group => 'id', + scope :with_validators, :group => 'id', :joins => 'INNER JOIN region_validators on (region_validators.region_id = categories.id)' end diff --git a/app/models/scrap.rb b/app/models/scrap.rb index 4fc3ac5..c9f8cbf 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -7,9 +7,9 @@ class Scrap < ActiveRecord::Base has_many :replies, :class_name => 'Scrap', :foreign_key => 'scrap_id', :dependent => :destroy belongs_to :root, :class_name => 'Scrap', :foreign_key => 'scrap_id' - named_scope :all_scraps, lambda {|profile| {:conditions => ["receiver_id = ? OR sender_id = ?", profile, profile], :limit => 30}} + scope :all_scraps, lambda {|profile| {:conditions => ["receiver_id = ? OR sender_id = ?", profile, profile], :limit => 30}} - named_scope :not_replies, :conditions => {:scrap_id => nil} + scope :not_replies, :conditions => {:scrap_id => nil} track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.receiver != s.sender}, :custom_target => :action_tracker_target diff --git a/app/models/task.rb b/app/models/task.rb index 8a6acf1..f2f4bec 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -45,7 +45,7 @@ class Task < ActiveRecord::Base end attr_accessor :code_length - before_validation_on_create do |task| + before_validation(:on => :create) do |task| if task.code.nil? task.code = Task.generate_code(task.code_length) while (Task.find_by_code(task.code)) @@ -266,16 +266,16 @@ class Task < ActiveRecord::Base end end - named_scope :pending, :conditions => { :status => Task::Status::ACTIVE } - named_scope :hidden, :conditions => { :status => Task::Status::HIDDEN } - named_scope :finished, :conditions => { :status => Task::Status::FINISHED } - named_scope :canceled, :conditions => { :status => Task::Status::CANCELLED } - named_scope :closed, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] } - named_scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } - named_scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } - named_scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } + scope :pending, :conditions => { :status => Task::Status::ACTIVE } + scope :hidden, :conditions => { :status => Task::Status::HIDDEN } + scope :finished, :conditions => { :status => Task::Status::FINISHED } + scope :canceled, :conditions => { :status => Task::Status::CANCELLED } + scope :closed, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] } + scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } + scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } + scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } - named_scope :to, lambda { |profile| + scope :to, lambda { |profile| environment_condition = nil if profile.person? envs_ids = Environment.find(:all).select{ |env| profile.is_admin?(env) }.map { |env| "target_id = #{env.id}"}.join(' OR ') diff --git a/app/models/text_article.rb b/app/models/text_article.rb index a07699e..7107227 100644 --- a/app/models/text_article.rb +++ b/app/models/text_article.rb @@ -1,3 +1,5 @@ +require 'noosfero/translatable_content' + # a base class for all text article types. class TextArticle < Article diff --git a/app/models/tiny_mce_article.rb b/app/models/tiny_mce_article.rb index ab2141a..63a1e08 100644 --- a/app/models/tiny_mce_article.rb +++ b/app/models/tiny_mce_article.rb @@ -1,3 +1,5 @@ +require 'white_list_filter' + class TinyMceArticle < TextArticle def self.short_description @@ -13,7 +15,10 @@ class TinyMceArticle < TextArticle xss_terminate :only => [ :name, :abstract, :body ], :with => 'white_list', :on => 'validation' include WhiteListFilter - filter_iframes :abstract, :body, :whitelist => lambda { profile && profile.environment && profile.environment.trusted_sites_for_iframe } + filter_iframes :abstract, :body + def iframe_whitelist + profile && profile.environment && profile.environment.trusted_sites_for_iframe + end def notifiable? true diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb index 6acb154..1ff1acc 100644 --- a/app/models/uploaded_file.rb +++ b/app/models/uploaded_file.rb @@ -1,3 +1,5 @@ +require 'short_filename' + # Article type that handles uploaded files. # # Limitation: only file metadata are versioned. Only the latest version diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..7cfb73b --- /dev/null +++ b/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Noosfero::Application diff --git a/config/application.rb b/config/application.rb index cddf354..4cf1657 100644 --- a/config/application.rb +++ b/config/application.rb @@ -9,21 +9,8 @@ if defined?(Bundler) # Bundler.require(:default, :assets, Rails.env) end -module Rails3 +module Noosfero class Application < Rails::Application - def noosfero_session_secret - require 'fileutils' - target_dir = File.join(File.dirname(__FILE__), '/../tmp') - FileUtils.mkdir_p(target_dir) - file = File.join(target_dir, 'session.secret') - if !File.exists?(file) - secret = (1..128).map { %w[0 1 2 3 4 5 6 7 8 9 a b c d e f][rand(16)] }.join('') - File.open(file, 'w') do |f| - f.puts secret - end - end - File.read(file).strip - end # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers @@ -87,13 +74,30 @@ module Rails3 # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' + def noosfero_session_secret + require 'fileutils' + target_dir = File.join(File.dirname(__FILE__), '../tmp') + FileUtils.mkdir_p(target_dir) + file = File.join(target_dir, 'session.secret') + if !File.exists?(file) + secret = (1..128).map { %w[0 1 2 3 4 5 6 7 8 9 a b c d e f][rand(16)] }.join('') + File.open(file, 'w') do |f| + f.puts secret + end + end + File.read(file).strip + end + # Your secret key for verifying cookie session data integrity. # If you change this key, all old sessions will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. + config.secret_token = noosfero_session_secret config.action_dispatch.session = { :key => '_noosfero_session', - :secret => noosfero_session_secret() } + + config.autoload_paths += Dir["#{config.root}/app/controllers/**/"] + end end diff --git a/config/environment.rb b/config/environment.rb index 60a1f43..bdd181d 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -7,35 +7,8 @@ require File.expand_path('../application', __FILE__) # extra directories for controllers organization extra_controller_dirs = %w[ - app/controllers/my_profile - app/controllers/admin - app/controllers/system - app/controllers/public ].map {|item| File.join(Rails.root, item) } -def noosfero_session_secret - require 'fileutils' - target_dir = File.join(File.dirname(__FILE__), '/../tmp') - FileUtils.mkdir_p(target_dir) - file = File.join(target_dir, 'session.secret') - if !File.exists?(file) - secret = (1..128).map { %w[0 1 2 3 4 5 6 7 8 9 a b c d e f][rand(16)] }.join('') - File.open(file, 'w') do |f| - f.puts secret - end - end - File.read(file).strip -end - -#FIXME controller_paths are no more supported on Rails 3 -#extra_controller_dirs.each do |item| -# $LOAD_PATH << item -# config.controller_paths << item -#end -#extra_controller_dirs.each do |item| -# (ActiveSupport.const_defined?('Dependencies') ? ActiveSupport::Dependencies : ::Dependencies).load_paths << item -#end - # Add new inflection rules using the following format # (all these examples are active by default): # Inflector.inflections do |inflect| @@ -65,4 +38,4 @@ if !['test', 'cucumber'].include?(ENV['RAILS_ENV']) end end -Rails3::Application.initialize! \ No newline at end of file +Noosfero::Application.initialize! diff --git a/config/environments/cucumber.rb b/config/environments/cucumber.rb index 773bb1b..cfb36c8 100644 --- a/config/environments/cucumber.rb +++ b/config/environments/cucumber.rb @@ -8,7 +8,6 @@ config.cache_classes = true # This must be true for Cucumber to operate correctl config.whiny_nils = true # Show full error reports and disable caching -config.action_controller.consider_all_requests_local = true config.action_controller.perform_caching = false # Disable request forgery protection in test environment diff --git a/config/environments/development.rb b/config/environments/development.rb index 829d94f..13a03d1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,4 @@ -Rails3::Application.configure do +Noosfero::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on @@ -10,7 +10,6 @@ Rails3::Application.configure do config.whiny_nils = true # Show full error reports and disable caching - config.action_controller.consider_all_requests_local = true config.action_controller.perform_caching = false # Don't care if the mailer can't send diff --git a/config/environments/production.rb b/config/environments/production.rb index 3c797cf..8bb0e02 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,4 +1,4 @@ -Rails3::Application.configure do +Noosfero::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The production environment is meant for finished, "live" apps. @@ -6,7 +6,6 @@ Rails3::Application.configure do config.cache_classes = true # Full error reports are disabled and caching is turned on - config.consider_all_requests_local = false config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) diff --git a/config/environments/test.rb b/config/environments/test.rb index ba2f579..cc7b7c5 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,4 +1,4 @@ -Rails3::Application.configure do +Noosfero::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's @@ -15,7 +15,6 @@ Rails3::Application.configure do config.whiny_nils = true # Show full error reports and disable caching - config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates @@ -34,4 +33,4 @@ Rails3::Application.configure do # Print deprecation notices to the stderr config.active_support.deprecation = :stderr -end \ No newline at end of file +end diff --git a/config/initializers/dependencies.rb b/config/initializers/dependencies.rb index dc1f8ff..6ffd190 100644 --- a/config/initializers/dependencies.rb +++ b/config/initializers/dependencies.rb @@ -7,6 +7,10 @@ require 'acts_as_having_boxes' require 'acts_as_having_image' require 'acts_as_having_posts' require 'route_if' +require 'maybe_add_http' +require 'set_profile_region_from_city_state' +require 'authenticated_system' +require 'needs_profile' # third-party libraries require 'will_paginate' diff --git a/config/routes.rb b/config/routes.rb index 57f172d..78a4419 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ require 'noosfero' -ActionController::Routing::Routes.draw do |map| +Noosfero::Application.routes.draw do # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: @@ -15,11 +15,15 @@ ActionController::Routing::Routes.draw do |map| ## Public controllers ###################################################### - map.connect 'test/:controller/:action/:id' , :controller => /.*test.*/ + match 'test/:controller(/:action(/:id))' , :controller => /.*test.*/ # -- just remember to delete public/index.html. # You can have the root of your site routed by hooking up '' - map.root :controller => "home", :conditions => { :if => lambda { |env| !Domain.hosting_profile_at(env[:host]) } } + root :to => 'home#index' + + # FIXME adapt the rest of the routes below +end +__END__ map.connect '', :controller => "home", :conditions => { :if => lambda { |env| !Domain.hosting_profile_at(env[:host]) } } map.home 'site/:action', :controller => 'home' diff --git a/debian/control b/debian/control index 64c4160..fc230a4 100644 --- a/debian/control +++ b/debian/control @@ -32,7 +32,6 @@ Depends: # ruby-gettext-rails, ruby-sqlite3, ruby-pg, - ruby-mysql, ruby-rmagick, ruby-redcloth, ruby-will-paginate (>= 2.3.12-1~), diff --git a/lib/acts_as_having_image.rb b/lib/acts_as_having_image.rb index 0ef9fff..9ddea12 100644 --- a/lib/acts_as_having_image.rb +++ b/lib/acts_as_having_image.rb @@ -3,8 +3,8 @@ module ActsAsHavingImage module ClassMethods def acts_as_having_image belongs_to :image - named_scope :with_image, :conditions => [ "#{table_name}.image_id IS NOT NULL" ] - named_scope :without_image, :conditions => [ "#{table_name}.image_id IS NULL" ] + scope :with_image, :conditions => [ "#{table_name}.image_id IS NOT NULL" ] + scope :without_image, :conditions => [ "#{table_name}.image_id IS NULL" ] self.send(:include, ActsAsHavingImage) end end diff --git a/lib/feed_handler.rb b/lib/feed_handler.rb index 64f638e..32bb9db 100644 --- a/lib/feed_handler.rb +++ b/lib/feed_handler.rb @@ -36,7 +36,7 @@ class FeedHandler content = "" block = lambda { |s| content = s.read } content = - if RAILS_ENV == 'test' && File.exists?(address) + if Rails.env == 'test' && File.exists?(address) File.read(address) else if !valid_url?(address) diff --git a/lib/noosfero.rb b/lib/noosfero.rb index ea41caa..0d686a6 100644 --- a/lib/noosfero.rb +++ b/lib/noosfero.rb @@ -80,9 +80,9 @@ module Noosfero end def self.url_options - if ENV['RAILS_ENV'] == 'development' + if Rails.env == 'development' development_url_options - elsif ENV['RAILS_ENV'] == 'cucumber' + elsif Rails.env == 'cucumber' Webrat.configuration.mode == :rails ? { :host => '' } : { :port => Webrat.configuration.application_port } else {} diff --git a/lib/noosfero/multi_tenancy.rb b/lib/noosfero/multi_tenancy.rb index d5d5057..d3c49cf 100644 --- a/lib/noosfero/multi_tenancy.rb +++ b/lib/noosfero/multi_tenancy.rb @@ -29,7 +29,7 @@ module Noosfero db_config = YAML.load_file(db_file) map = { } db_config.each do |env, attr| - next unless env.match(/_#{RAILS_ENV}$/) and attr['adapter'] =~ /^postgresql$/i + next unless env.match(/_#{Rails.env}$/) and attr['adapter'] =~ /^postgresql$/i attr['domains'].each { |d| map[d] = attr['schema_search_path'] } end map @@ -38,7 +38,7 @@ module Noosfero def self.is_hosted_environment? db_file = File.join(Rails.root, 'config', 'database.yml') db_config = YAML.load_file(db_file) - db_config.select{ |env, attr| RAILS_ENV.to_s.match(/_#{env}$/) }.any? + db_config.select{ |env, attr| Rails.env.to_s.match(/_#{env}$/) }.any? end end diff --git a/lib/route_if.rb b/lib/route_if.rb index 4bd637a..1ae96cf 100644 --- a/lib/route_if.rb +++ b/lib/route_if.rb @@ -1,18 +1 @@ -require 'action_controller/routing' - -class ActionController::Routing::RouteSet - alias :orig_extract_request_environment :extract_request_environment - def extract_request_environment(request) - orig_extract_request_environment(request).merge(:host => request.host) - end -end - -class ActionController::Routing::Route - alias :orig_recognition_conditions :recognition_conditions - def recognition_conditions - result = orig_recognition_conditions - result << "conditions[:if].call(env)" if conditions[:if] - result - end -end - +# FIXME implement conditional routing wrt Rails 3 here diff --git a/lib/tasks/release.rake b/lib/tasks/release.rake index 4acaa91..6ed48be 100644 --- a/lib/tasks/release.rake +++ b/lib/tasks/release.rake @@ -1,3 +1,5 @@ +# encoding: UTF-8 + namespace :noosfero do desc 'checks if there are uncommitted changes in the repo' diff --git a/lib/white_list_filter.rb b/lib/white_list_filter.rb index 33da203..5c2d29f 100644 --- a/lib/white_list_filter.rb +++ b/lib/white_list_filter.rb @@ -21,11 +21,11 @@ module WhiteListFilter module ClassMethods def filter_iframes(*opts) - options = opts.pop - white_list_method = options[:whitelist] + options = opts.last.is_a?(Hash) && opts.pop || {} + white_list_method = options[:whitelist] || :iframe_whitelist opts.each do |field| before_validation do |obj| - obj.check_iframe_on_content(obj.send(field), obj.instance_eval(&white_list_method)) + obj.check_iframe_on_content(obj.send(field), obj.send(white_list_method)) end end end diff --git a/script/debundler b/script/debundler new file mode 100755 index 0000000..6ea9068 --- /dev/null +++ b/script/debundler @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby + + +cache = '/tmp/debundler.' + ENV['USER'] + '.cache.yaml' +unless File.exists?(cache) + unless system("apt-file search /usr/share/rubygems-integration/1.9.1 > #{cache}") + exit 1 + end +end + +$gems = [] +def source(s) +end +def gem(n, v = nil) + $gems << n +end +load './Gemfile' + +require 'yaml' +deb2gem = YAML.load_file(cache) +gem2deb = {} +deb2gem.each do |package,spec| + gem_info = File.basename(spec).sub(/\.gemspec$/, '').split('-') + gem_version = gem_info.pop + gem_name = gem_info.join('-') + gem2deb[gem_name] = package +end + +packages = [] +$gems.each do |g| + package = gem2deb[g] + if package + packages << package + else + puts "E: gem #{g} not found" + not_found += 1 + end +end + +if packages.size == $gems.size + system("sudo apt-get -y install #{packages.join(" ")}") +else + exit 1 +end diff --git a/script/install-dependencies/debian-sid.sh b/script/install-dependencies/debian-sid.sh new file mode 120000 index 0000000..f26144d --- /dev/null +++ b/script/install-dependencies/debian-sid.sh @@ -0,0 +1 @@ +debian-wheezy.sh \ No newline at end of file diff --git a/script/install-dependencies/debian-wheezy.sh b/script/install-dependencies/debian-wheezy.sh index af0474c..fd1d656 100644 --- a/script/install-dependencies/debian-wheezy.sh +++ b/script/install-dependencies/debian-wheezy.sh @@ -1,10 +1,13 @@ # needed to run noosfero -runtime_dependencies=$(sed -e '1,/^Depends:/d; /^Recommends:/,$ d; s/([^)]*)//g; s/,\s*/\n/g' debian/control | grep -v 'memcached\|debconf\|dbconfig-common\|postgresql\|misc:Depends\|adduser\|mail-transport-agent') +runtime_dependencies=$(sed -e '/^\s*#/d; 1,/^Depends:/d; /^Recommends:/,$ d; s/([^)]*)//g; s/,\s*/\n/g' debian/control | grep -v 'memcached\|debconf\|dbconfig-common\|postgresql\|misc:Depends\|adduser\|mail-transport-agent') run sudo apt-get -y install $runtime_dependencies sudo apt-get -y install iceweasel || sudo apt-get -y install firefox # needed for development run sudo apt-get -y install ruby-tidy ruby-mocha imagemagick po4a xvfb libxml2-dev libxslt1-dev -gem which bundler >/dev/null 2>&1 || gem_install bundler -setup_rubygems_path -run bundle install + +sudo apt-get -y install bundler + +run ./script/debundler + +run bundle --local diff --git a/test/unit/countries_helper_test.rb b/test/unit/countries_helper_test.rb index 9d65b72..29bf8e5 100644 --- a/test/unit/countries_helper_test.rb +++ b/test/unit/countries_helper_test.rb @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../test_helper' class CountriesHelperTest < ActiveSupport::TestCase def setup - @helper = CountriesHelper.instance + @helper = CountriesHelper::Object.instance end attr_reader :helper diff --git a/vendor/plugins/access_control/lib/role.rb b/vendor/plugins/access_control/lib/role.rb index 5f114a0..78f9ee0 100644 --- a/vendor/plugins/access_control/lib/role.rb +++ b/vendor/plugins/access_control/lib/role.rb @@ -6,7 +6,7 @@ class Role < ActiveRecord::Base validates_presence_of :name validates_uniqueness_of :name, :scope => :environment_id validates_uniqueness_of :key, :if => lambda { |role| !role.key.blank? }, :scope => :environment_id - before_validation_on_create :create_key + before_validation :create_key, :on => :create def initialize(*args) super(*args) diff --git a/vendor/plugins/action_tracker/lib/action_tracker_model.rb b/vendor/plugins/action_tracker/lib/action_tracker_model.rb index a711aeb..6f50fbd 100644 --- a/vendor/plugins/action_tracker/lib/action_tracker_model.rb +++ b/vendor/plugins/action_tracker/lib/action_tracker_model.rb @@ -23,8 +23,8 @@ module ActionTracker # In days RECENT_DELAY = 30 - named_scope :recent, :conditions => ['created_at >= ?', RECENT_DELAY.days.ago] - named_scope :visible, :conditions => { :visible => true } + scope :recent, :conditions => ['created_at >= ?', RECENT_DELAY.days.ago] + scope :visible, :conditions => { :visible => true } def self.current_user_from_model u = new diff --git a/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb b/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb index 19fca35..77fab8a 100644 --- a/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb +++ b/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb @@ -132,7 +132,7 @@ module Technoweenie # :nodoc: end def self.extended(base) - base.class_inheritable_accessor :attachment_options + base.class_attribute :attachment_options base.before_destroy :destroy_thumbnails base.before_validation :set_size_from_temp_path base.after_save :after_process_attachment diff --git a/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb b/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb index e63d1e7..e314c8d 100644 --- a/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb +++ b/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/backends/file_system_backend.rb @@ -1,4 +1,3 @@ -require 'ftools' module Technoweenie # :nodoc: module AttachmentFu # :nodoc: module Backends diff --git a/vendor/plugins/delayed_job/lib/delayed/backend/active_record.rb b/vendor/plugins/delayed_job/lib/delayed/backend/active_record.rb index f06604a..6a17b4d 100644 --- a/vendor/plugins/delayed_job/lib/delayed/backend/active_record.rb +++ b/vendor/plugins/delayed_job/lib/delayed/backend/active_record.rb @@ -32,10 +32,10 @@ module Delayed } scope :by_priority, order('priority ASC, run_at ASC') else - named_scope :ready_to_run, lambda {|worker_name, max_run_time| + scope :ready_to_run, lambda {|worker_name, max_run_time| {:conditions => ['(run_at <= ? AND (locked_at IS NULL OR locked_at < ?) OR locked_by = ?) AND failed_at IS NULL', db_time_now, db_time_now - max_run_time, worker_name]} } - named_scope :by_priority, :order => 'priority ASC, run_at ASC' + scope :by_priority, :order => 'priority ASC, run_at ASC' end def self.after_fork diff --git a/vendor/plugins/delayed_job/lib/delayed/yaml_ext.rb b/vendor/plugins/delayed_job/lib/delayed/yaml_ext.rb index 8d38d5b..2e937b3 100644 --- a/vendor/plugins/delayed_job/lib/delayed/yaml_ext.rb +++ b/vendor/plugins/delayed_job/lib/delayed/yaml_ext.rb @@ -25,11 +25,6 @@ class Module end -class Class - yaml_as "tag:ruby.yaml.org,2002:class" - remove_method :to_yaml # use Module's to_yaml -end - class Struct def self.yaml_tag_read_class(name) # Constantize the object so that ActiveSupport can attempt diff --git a/vendor/plugins/monkey_patches/attachment_fu_validates_attachment/init.rb b/vendor/plugins/monkey_patches/attachment_fu_validates_attachment/init.rb index 663970c..8862e71 100644 --- a/vendor/plugins/monkey_patches/attachment_fu_validates_attachment/init.rb +++ b/vendor/plugins/monkey_patches/attachment_fu_validates_attachment/init.rb @@ -27,7 +27,7 @@ Technoweenie::AttachmentFu::ClassMethods.module_eval do # :size => "The image you uploaded was larger than the maximum size of 10MB" def validates_attachment(options={}) options[:empty] ||= "No file uploaded" - class_inheritable_accessor :attachment_validation_options + class_attribute :attachment_validation_options self.attachment_validation_options = options validate :attachment_valid? end diff --git a/vendor/plugins/monkey_patches/init.rb b/vendor/plugins/monkey_patches/init.rb new file mode 100644 index 0000000..4eb6fce --- /dev/null +++ b/vendor/plugins/monkey_patches/init.rb @@ -0,0 +1 @@ +require File.join(File.dirname(__FILE__), 'attachment_fu_validates_attachment/init') diff --git a/vendor/plugins/monkey_patches/methods_from_fake_arel/init.rb b/vendor/plugins/monkey_patches/methods_from_fake_arel/init.rb deleted file mode 100644 index 817f52b..0000000 --- a/vendor/plugins/monkey_patches/methods_from_fake_arel/init.rb +++ /dev/null @@ -1,71 +0,0 @@ -# monkey patch to add fake_arel select, or_scope and where methods -# this gem requires activesupport-2.3.14 and activerecord-2.3.14 -# -# https://github.com/gammons/fake_arel - -module Rails3Finder - def self.included(base) - base.class_eval do - - # the default named scopes - named_scope :offset, lambda {|offset| {:offset => offset}} - named_scope :limit, lambda {|limit| {:limit => limit}} - named_scope :includes, lambda { |*includes| { :include => includes }} - named_scope :order, lambda {|*order| {:order => order.join(',') }} - named_scope :joins, lambda {|*join| {:joins => join } if join[0]} - named_scope :from, lambda {|*from| {:from => from }} - named_scope :having, lambda {|*having| {:having => having }} - named_scope :group, lambda {|*group| {:group => group.join(',') }} - named_scope :readonly, lambda {|readonly| {:readonly => readonly }} - named_scope :lock, lambda {|lock| {:lock => lock }} - - def self.select(value = Proc.new) - if block_given? - all.select {|*block_args| value.call(*block_args) } - else - self.scoped(:select => Array.wrap(value).join(',')) - end - end - - __where_fn = lambda do |*where| - if where.is_a?(Array) and where.size == 1 - {:conditions => where.first} - else - {:conditions => where} - end - end - - named_scope :where, __where_fn - - # Use carefully this method! It might get lost with different classes - # scopes or different types of joins. - def self.or_scope(*scopes) - where = [] - joins = [] - includes = [] - - # for some reason, flatten is actually executing the scope - scopes = scopes[0] if scopes.size == 1 - scopes.each do |s| - s = s.proxy_options - begin - where << merge_conditions(s[:conditions]) - rescue NoMethodError - # I am ActiveRecord::Base. Only my subclasses define merge_conditions: - where << subclasses.first.merge_conditions(s[:conditions]) - end - #where << merge_conditions(s[:conditions]) - joins << s[:joins] unless s[:joins].nil? - includes << s[:include] unless s[:include].nil? - end - scoped = self - scoped = scoped.select("DISTINCT #{self.table_name}.*") - scoped = scoped.includes(includes.uniq.flatten) unless includes.blank? - scoped = scoped.joins(joins.uniq.flatten) unless joins.blank? - scoped.where(where.join(" OR ")) - end - end - end -end - -ActiveRecord::Base.send :include, Rails3Finder diff --git a/vendor/plugins/nested_has_many_through/.gitignore b/vendor/plugins/nested_has_many_through/.gitignore deleted file mode 100644 index 57f3a0b..0000000 --- a/vendor/plugins/nested_has_many_through/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.garlic -doc/* diff --git a/vendor/plugins/nested_has_many_through/CHANGELOG b/vendor/plugins/nested_has_many_through/CHANGELOG deleted file mode 100644 index 2a62803..0000000 --- a/vendor/plugins/nested_has_many_through/CHANGELOG +++ /dev/null @@ -1,4 +0,0 @@ -* spec'd and fixed some problems with using named_scope in edge - -* Initial commit - diff --git a/vendor/plugins/nested_has_many_through/MIT-LICENSE b/vendor/plugins/nested_has_many_through/MIT-LICENSE deleted file mode 100644 index 906139d..0000000 --- a/vendor/plugins/nested_has_many_through/MIT-LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2008 Ian White - ian.w.white@gmail.com - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/vendor/plugins/nested_has_many_through/README.rdoc b/vendor/plugins/nested_has_many_through/README.rdoc deleted file mode 100755 index 03f01f6..0000000 --- a/vendor/plugins/nested_has_many_through/README.rdoc +++ /dev/null @@ -1,92 +0,0 @@ -http://plugins.ardes.com > nested_has_many_through - -= nested_has_many_through - -A fantastic patch/plugin has been floating around for a while: - -* http://dev.rubyonrails.org/ticket/6461 -* http://code.torchbox.com/svn/rails/plugins/nested_has_many_through - -obrie made the original ticket and Matt Westcott released the first version of -the plugin, under the MIT license. Many others have contributed, see the trac -ticket for details. - -Here is a refactored version (I didn't write the original), suitable for edge/2.0-stable -with a bunch of acceptance specs. I'm concentrating on plugin usage, once -it becomes stable, and well enough speced/understood, then it's time to pester -rails-core. - -== Why republish this on github? - -* The previous implementations are very poorly speced/tested, so it's pretty - hard to refactor and understand this complicated bit of sql-fu, especially - when you're aiming at a moving target (edge) -* the lastest patches don't apply on edge -* github - let's collab to make this better and get a patch accepted, fork away! - -== Help out - -I'm releasing 'early and often' in the hope that people will use it and find bugs/problems. -Report them at http://ianwhite.lighthouseapp.com, or fork and pull request, yada yada. - -== History - -Here's the original description: - - This plugin makes it possible to define has_many :through relationships that - go through other has_many :through relationships, possibly through an - arbitrarily deep hierarchy. This allows associations across any number of - tables to be constructed, without having to resort to find_by_sql (which isn't - a suitable solution if you need to do eager loading through :include as well). - -== Contributors - -* Matt Westcott -* terceiro -* shoe -* mhoroschun -* Ian White (http://github.com/ianwhite) -* Claudio (http://github.com/masterkain) - -Get in touch if you should be on this list - -== Show me the money! - -Here's some models from the specs: - - class Author < User - has_many :posts - has_many :categories, :through => :posts, :uniq => true - has_many :similar_posts, :through => :categories, :source => :posts - has_many :similar_authors, :through => :similar_posts, :source => :author, :uniq => true - has_many :posts_of_similar_authors, :through => :similar_authors, :source => :posts, :uniq => true - has_many :commenters, :through => :posts, :uniq => true - end - - class Post < ActiveRecord::Base - belongs_to :author - belongs_to :category - has_many :comments - has_many :commenters, :through => :comments, :source => :user, :uniq => true - end - -The first two has_manys of Author are plain vanilla, the last four are what this plugin enables - - # has_many through a has_many :through - has_many :similar_posts, :through => :categories, :source => :posts - - # doubly nested has_many :through - has_many :similar_authors, :through => :similar_posts, :source => :author, :uniq => true - - # whoah! - has_many :posts_of_similar_authors, :through => :similar_authors, :source => :posts, :uniq => true - - # has_many through a has_many :through in another model - has_many :commenters, :through => :posts, :uniq => true - -== What does it run on? - -Currently it's running on 2.0, 2.1, and 2.2 stable branches - -If you want to run the CI suite, then check out garlic_example.rb (The CI suite -is being cooked with garlic - git://github.com/ianwhite/garlic) diff --git a/vendor/plugins/nested_has_many_through/Rakefile b/vendor/plugins/nested_has_many_through/Rakefile deleted file mode 100644 index ecc8b5f..0000000 --- a/vendor/plugins/nested_has_many_through/Rakefile +++ /dev/null @@ -1,77 +0,0 @@ -# use pluginized rpsec if it exists -rspec_base = File.expand_path(File.dirname(__FILE__) + '/../rspec/lib') -$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base) and !$LOAD_PATH.include?(rspec_base) - -require 'spec/rake/spectask' -require 'spec/rake/verify_rcov' -require 'rake/rdoctask' - -plugin_name = 'nested_has_many_through' - -task :default => :spec - -desc "Run the specs for #{plugin_name}" -Spec::Rake::SpecTask.new(:spec) do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] - t.spec_opts = ["--colour"] -end - -namespace :spec do - desc "Generate RCov report for #{plugin_name}" - Spec::Rake::SpecTask.new(:rcov) do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] - t.rcov = true - t.rcov_dir = 'doc/coverage' - t.rcov_opts = ['--text-report', '--exclude', "spec/,rcov.rb,#{File.expand_path(File.join(File.dirname(__FILE__),'../../..'))}"] - end - - namespace :rcov do - desc "Verify RCov threshold for #{plugin_name}" - RCov::VerifyTask.new(:verify => "spec:rcov") do |t| - t.threshold = 97.1 - t.index_html = File.join(File.dirname(__FILE__), 'doc/coverage/index.html') - end - end - - desc "Generate specdoc for #{plugin_name}" - Spec::Rake::SpecTask.new(:doc) do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] - t.spec_opts = ["--format", "specdoc:SPECDOC"] - end - - namespace :doc do - desc "Generate html specdoc for #{plugin_name}" - Spec::Rake::SpecTask.new(:html => :rdoc) do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] - t.spec_opts = ["--format", "html:doc/rspec_report.html", "--diff"] - end - end -end - -task :rdoc => :doc -task "SPECDOC" => "spec:doc" - -desc "Generate rdoc for #{plugin_name}" -Rake::RDocTask.new(:doc) do |t| - t.rdoc_dir = 'doc' - t.main = 'README.rdoc' - t.title = "#{plugin_name}" - t.template = ENV['RDOC_TEMPLATE'] - t.options = ['--line-numbers', '--inline-source'] - t.rdoc_files.include('README.rdoc', 'SPECDOC', 'MIT-LICENSE') - t.rdoc_files.include('lib/**/*.rb') -end - -namespace :doc do - desc "Generate all documentation (rdoc, specdoc, specdoc html and rcov) for #{plugin_name}" - task :all => ["spec:doc:html", "spec:doc", "spec:rcov", "doc"] -end - -task :cruise do - # run the garlic task, capture the output, if succesful make the docs and copy them to ardes - sh "garlic all" - `garlic run > .garlic/report.txt` - `scp -i ~/.ssh/ardes .garlic/report.txt ardes@ardes.com:~/subdomains/plugins/httpdocs/doc/#{plugin_name}_garlic_report.txt` - `cd .garlic/*/vendor/plugins/#{plugin_name}; rake doc:all; scp -i ~/.ssh/ardes -r doc ardes@ardes.com:~/subdomains/plugins/httpdocs/doc/#{plugin_name}` - puts "The build is GOOD" -end diff --git a/vendor/plugins/nested_has_many_through/SPECDOC b/vendor/plugins/nested_has_many_through/SPECDOC deleted file mode 100644 index 6ce019f..0000000 --- a/vendor/plugins/nested_has_many_through/SPECDOC +++ /dev/null @@ -1,49 +0,0 @@ - -Author (newly created) -- #posts should == [] -- #categories should == [] -- #similar_posts should == [] -- #similar_authors should == [] -- #commenters should == [] - -Author (newly created) who creates post with category -- #posts should == [post] -- #categories should == [category] - -Author (newly created) who creates post with category and @other_author creates post2 in category -- #posts should == [post2] -- #categories should == [category] -- #similar_posts.should == [post, post2] -- #similar_authors.should == [@author, @other_author] - -Author (newly created) who creates post with category and @other_author creates post2 in category and creates @other_post in @other_category -- #similar_posts.should == [@post, @post2] -- #posts_by_similar_authors.should == [@post, @post2, @other_post] - -Commenter use case (a1: p1>c1, a2: p2>c1, p3>c2, a3: p4>c3) -- a1.posts should == [p1] -- a1.categories should == [c1] -- a2.posts should == [p2, p3] -- a2.categories should == [c1, c2] - -Commenter use case (a1: p1>c1, a2: p2>c1, p3>c2, a3: p4>c3) u1 comments on p2 -- u1.comments should == [comment] -- a1.commenters should be empty -- a2.commenters should == [u1] -- u1.commented_posts should == [p2] -- u1.commented_posts.find_inflamatory(:all) should be empty -- u1.commented_posts.inflamatory should be empty -- u1.commented_authors should == [a2] -- u1.posts_of_interest should == [p1, p2, p3] -- u1.categories_of_interest should == [c1, c2] - -Commenter use case (a1: p1>c1, a2: p2>c1, p3>c2, a3: p4>c3) u1 comments on p2 when p2 is inflamatory -- p2 should be inflamatory -- u1.commented_posts.find_inflamatory(:all) should == [p2] -- u1.posts_of_interest.find_inflamatory(:all) should == [p2] -- u1.commented_posts.inflamatory should == [p2] -- u1.posts_of_interest.inflamatory should == [p2] - -Finished in 0.538693 seconds - -31 examples, 0 failures diff --git a/vendor/plugins/nested_has_many_through/TODO b/vendor/plugins/nested_has_many_through/TODO deleted file mode 100644 index 76e4409..0000000 --- a/vendor/plugins/nested_has_many_through/TODO +++ /dev/null @@ -1,10 +0,0 @@ -* get C2 up to 100% - - spec a polymorphic relationship - -* quote table names - -* make more use of rails in construct_has_many_or_belongs_to_attributes to reduce brittleness - -* Add more coverage - - scopes - - raise an error when nhmt is being used in a perverse way \ No newline at end of file diff --git a/vendor/plugins/nested_has_many_through/garlic.rb b/vendor/plugins/nested_has_many_through/garlic.rb deleted file mode 100644 index 57c0b85..0000000 --- a/vendor/plugins/nested_has_many_through/garlic.rb +++ /dev/null @@ -1,27 +0,0 @@ -garlic do - repo 'nested_has_many_through', :path => '.' - - repo 'rails', :url => 'git://github.com/rails/rails' - repo 'rspec', :url => 'git://github.com/dchelimsky/rspec' - repo 'rspec-rails', :url => 'git://github.com/dchelimsky/rspec-rails' - - # target rails versions - ['origin/2-2-stable', 'origin/2-1-stable', 'origin/2-0-stable'].each do |rails| - # specify how to prepare app and run CI task - target "Rails: #{rails}", :tree_ish => rails do - prepare do - plugin 'rspec' - plugin 'rspec-rails' do - `script/generate rspec -f` - end - plugin 'nested_has_many_through', :clone => true - end - - run do - cd "vendor/plugins/nested_has_many_through" do - sh "rake spec:rcov:verify" - end - end - end - end -end diff --git a/vendor/plugins/nested_has_many_through/init.rb b/vendor/plugins/nested_has_many_through/init.rb deleted file mode 100644 index ccd759b..0000000 --- a/vendor/plugins/nested_has_many_through/init.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'nested_has_many_through' - -ActiveRecord::Associations::HasManyThroughAssociation.send :include, NestedHasManyThrough::Association - -# BC -if defined?(ActiveRecord::Reflection::ThroughReflection) - ActiveRecord::Reflection::ThroughReflection.send :include, NestedHasManyThrough::Reflection -else - ActiveRecord::Reflection::AssociationReflection.send :include, NestedHasManyThrough::Reflection -end \ No newline at end of file diff --git a/vendor/plugins/nested_has_many_through/lib/nested_has_many_through.rb b/vendor/plugins/nested_has_many_through/lib/nested_has_many_through.rb deleted file mode 100644 index 958efb7..0000000 --- a/vendor/plugins/nested_has_many_through/lib/nested_has_many_through.rb +++ /dev/null @@ -1,148 +0,0 @@ -module NestedHasManyThrough - module Reflection # :nodoc: - def self.included(base) - base.send :alias_method_chain, :check_validity!, :nested_has_many_through - end - - def check_validity_with_nested_has_many_through! - check_validity_without_nested_has_many_through! - rescue ActiveRecord::HasManyThroughSourceAssociationMacroError => e - # now we permit has many through to a :though source - raise e unless source_reflection.options[:through] - end - end - - module Association - def self.included(base) - base.class_eval do - alias_method :original_construct_conditions, :construct_conditions - alias_method :original_construct_joins, :construct_joins - - def construct_conditions - if @reflection.macro == :has_one - original_construct_conditions - else - @nested_join_attributes ||= construct_nested_join_attributes - "#{@nested_join_attributes[:remote_key]} = #{@owner.quoted_id} #{@nested_join_attributes[:conditions]}" - end - end - - def construct_joins(custom_joins = nil) - if @reflection.macro == :has_one - original_construct_joins(custom_joins) - else - @nested_join_attributes ||= construct_nested_join_attributes - "#{@nested_join_attributes[:joins]} #{custom_joins}" - end - end - end - end - - protected - # Given any belongs_to or has_many (including has_many :through) association, - # return the essential components of a join corresponding to that association, namely: - # - # * :joins: any additional joins required to get from the association's table - # (reflection.table_name) to the table that's actually joining to the active record's table - # * :remote_key: the name of the key in the join table (qualified by table name) which will join - # to a field of the active record's table - # * :local_key: the name of the key in the local table (not qualified by table name) which will - # take part in the join - # * :conditions: any additional conditions (e.g. filtering by type for a polymorphic association, - # or a :conditions clause explicitly given in the association), including a leading AND - def construct_nested_join_attributes( reflection = @reflection, - association_class = reflection.klass, - table_ids = {association_class.table_name => 1}) - if reflection.macro == :has_many && reflection.through_reflection - construct_has_many_through_attributes(reflection, table_ids) - else - construct_has_many_or_belongs_to_attributes(reflection, association_class, table_ids) - end - end - - def construct_has_many_through_attributes(reflection, table_ids) - # Construct the join components of the source association, so that we have a path from - # the eventual target table of the association up to the table named in :through, and - # all tables involved are allocated table IDs. - source_attrs = construct_nested_join_attributes(reflection.source_reflection, reflection.klass, table_ids) - - # Determine the alias of the :through table; this will be the last table assigned - # when constructing the source join components above. - through_table_alias = through_table_name = reflection.through_reflection.table_name - through_table_alias += "_#{table_ids[through_table_name]}" unless table_ids[through_table_name] == 1 - - # Construct the join components of the through association, so that we have a path to - # the active record's table. - through_attrs = construct_nested_join_attributes(reflection.through_reflection, reflection.through_reflection.klass, table_ids) - - # Any subsequent joins / filters on owner attributes will act on the through association, - # so that's what we return for the conditions/keys of the overall association. - conditions = through_attrs[:conditions] - conditions += " AND #{interpolate_sql(reflection.klass.send(:sanitize_sql, reflection.options[:conditions]))}" if reflection.options[:conditions] - - { - :joins => "%s INNER JOIN %s ON ( %s = %s.%s %s) %s %s" % [ - source_attrs[:joins], - through_table_name == through_table_alias ? through_table_name : "#{through_table_name} #{through_table_alias}", - source_attrs[:remote_key], - through_table_alias, source_attrs[:local_key], - source_attrs[:conditions], - through_attrs[:joins], - reflection.options[:joins] - ], - :remote_key => through_attrs[:remote_key], - :local_key => through_attrs[:local_key], - :conditions => conditions - } - end - - - # reflection is not has_many :through; it's a standard has_many / belongs_to instead - # TODO: see if we can defer to rails code here a bit more - def construct_has_many_or_belongs_to_attributes(reflection, association_class, table_ids) - # Determine the alias used for remote_table_name, if any. In all cases this will already - # have been assigned an ID in table_ids (either through being involved in a previous join, - # or - if it's the first table in the query - as the default value of table_ids) - remote_table_alias = remote_table_name = association_class.table_name - remote_table_alias += "_#{table_ids[remote_table_name]}" unless table_ids[remote_table_name] == 1 - - # Assign a new alias for the local table. - local_table_alias = local_table_name = reflection.active_record.table_name - if table_ids[local_table_name] - table_id = table_ids[local_table_name] += 1 - local_table_alias += "_#{table_id}" - else - table_ids[local_table_name] = 1 - end - - conditions = '' - # Add filter for single-table inheritance, if applicable. - conditions += " AND #{remote_table_alias}.#{association_class.inheritance_column} = #{association_class.quote_value(association_class.name.demodulize)}" unless association_class.descends_from_active_record? - # Add custom conditions - conditions += " AND (#{interpolate_sql(association_class.send(:sanitize_sql, reflection.options[:conditions]))})" if reflection.options[:conditions] - - if reflection.macro == :belongs_to - if reflection.options[:polymorphic] - conditions += " AND #{local_table_alias}.#{reflection.options[:foreign_type]} = #{reflection.active_record.quote_value(association_class.base_class.name.to_s)}" - end - { - :joins => reflection.options[:joins], - :remote_key => "#{remote_table_alias}.#{association_class.primary_key}", - :local_key => reflection.primary_key_name, - :conditions => conditions - } - else - # Association is has_many (without :through) - if reflection.options[:as] - conditions += " AND #{remote_table_alias}.#{reflection.options[:as]}_type = #{reflection.active_record.quote_value(reflection.active_record.base_class.name.to_s)}" - end - { - :joins => "#{reflection.options[:joins]}", - :remote_key => "#{remote_table_alias}.#{reflection.primary_key_name}", - :local_key => reflection.klass.primary_key, - :conditions => conditions - } - end - end - end -end diff --git a/vendor/plugins/nested_has_many_through/spec/app.rb b/vendor/plugins/nested_has_many_through/spec/app.rb deleted file mode 100644 index 71c7c4e..0000000 --- a/vendor/plugins/nested_has_many_through/spec/app.rb +++ /dev/null @@ -1,84 +0,0 @@ -# Testing app setup - -################## -# Database schema -################## - -ActiveRecord::Migration.suppress_messages do - ActiveRecord::Schema.define(:version => 0) do - create_table :users, :force => true do |t| - t.column "type", :string - end - - create_table :posts, :force => true do |t| - t.column "author_id", :integer - t.column "category_id", :integer - t.column "inflamatory", :boolean - end - - create_table :categories, :force => true do |t| - end - - create_table :comments, :force => true do |t| - t.column "user_id", :integer - t.column "post_id", :integer - end - end -end - -######### -# Models -# -# Domain model is this: -# -# - authors (type of user) can create posts in categories -# - users can comment on posts -# - authors have similar_posts: posts in the same categories as ther posts -# - authors have similar_authors: authors of the recommended_posts -# - authors have posts_of_similar_authors: all posts by similar authors (not just the similar posts, -# similar_posts is be a subset of this collection) -# - authors have commenters: users who have commented on their posts -# -class User < ActiveRecord::Base - has_many :comments - has_many :commented_posts, :through => :comments, :source => :post, :uniq => true - has_many :commented_authors, :through => :commented_posts, :source => :author, :uniq => true - has_many :posts_of_interest, :through => :commented_authors, :source => :posts_of_similar_authors, :uniq => true - has_many :categories_of_interest, :through => :posts_of_interest, :source => :category, :uniq => true -end - -class Author < User - has_many :posts - has_many :categories, :through => :posts - has_many :similar_posts, :through => :categories, :source => :posts - has_many :similar_authors, :through => :similar_posts, :source => :author, :uniq => true - has_many :posts_of_similar_authors, :through => :similar_authors, :source => :posts, :uniq => true - has_many :commenters, :through => :posts, :uniq => true -end - -class Post < ActiveRecord::Base - - # testing with_scope - def self.find_inflamatory(*args) - with_scope :find => {:conditions => {:inflamatory => true}} do - find(*args) - end - end - - # only test named_scope in edge - named_scope(:inflamatory, :conditions => {:inflamatory => true}) if respond_to?(:named_scope) - - belongs_to :author - belongs_to :category - has_many :comments - has_many :commenters, :through => :comments, :source => :user, :uniq => true -end - -class Category < ActiveRecord::Base - has_many :posts -end - -class Comment < ActiveRecord::Base - belongs_to :user - belongs_to :post -end \ No newline at end of file diff --git a/vendor/plugins/nested_has_many_through/spec/models/author_spec.rb b/vendor/plugins/nested_has_many_through/spec/models/author_spec.rb deleted file mode 100644 index 36ccf18..0000000 --- a/vendor/plugins/nested_has_many_through/spec/models/author_spec.rb +++ /dev/null @@ -1,85 +0,0 @@ -require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper')) -require File.expand_path(File.join(File.dirname(__FILE__), '../app')) - -describe Author do - describe "(newly created)" do - before do - @category = Category.create! - @other_category = Category.create! - @author = Author.create! - end - - it "#posts should == []" do - @author.posts.should == [] - end - - it "#categories should == []" do - @author.categories.should == [] - end - - it "#similar_posts should == []" do - @author.similar_posts.should == [] - end - - it "#similar_authors should == []" do - @author.similar_authors.should == [] - end - - it "#commenters should == []" do - @author.commenters.should == [] - end - - describe "who creates post with category" do - before do - @post = Post.create! :author => @author, :category => @category - end - - it "#posts should == [post]" do - @author.posts.should == [@post] - end - - it "#categories should == [category]" do - @author.categories.should == [@category] - end - - describe "and @other_author creates post2 in category" do - - before do - @other_author = Author.create! - @post2 = Post.create! :author => @other_author, :category => @category - end - - it "#posts should == [post2]" do - @author.posts.should == [@post] - end - - it "#categories should == [category]" do - @author.categories.should == [@category] - end - - it "#similar_posts.should == [post, post2]" do - @author.similar_posts.should == [@post, @post2] - end - - it "#similar_authors.should == [@author, @other_author]" do - @author.similar_authors.should == [@author, @other_author] - end - - describe "and creates @other_post in @other_category" do - before do - @other_category = Category.create! - @other_post = Post.create! :author => @other_author, :category => @other_category - end - - it "#similar_posts.should == [@post, @post2]" do - @author.similar_posts.should == [@post, @post2] - end - - it "#posts_by_similar_authors.should == [@post, @post2, @other_post]" do - @author.posts_of_similar_authors.should == [@post, @post2, @other_post] - end - end - end - end - end -end \ No newline at end of file diff --git a/vendor/plugins/nested_has_many_through/spec/models/commenter_spec.rb b/vendor/plugins/nested_has_many_through/spec/models/commenter_spec.rb deleted file mode 100644 index b57b3ce..0000000 --- a/vendor/plugins/nested_has_many_through/spec/models/commenter_spec.rb +++ /dev/null @@ -1,109 +0,0 @@ -require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper')) -require File.expand_path(File.join(File.dirname(__FILE__), '../app')) - -describe 'Commenter use case (a1: p1>c1, a2: p2>c1, p3>c2, a3: p4>c3)' do - before do - @c1 = Category.create! - @c2 = Category.create! - @c3 = Category.create! - @a1 = Author.create! - @a2 = Author.create! - @a3 = Author.create! - @p1 = @a1.posts.create! :category => @c1 - @p2 = @a2.posts.create! :category => @c1 - @p3 = @a2.posts.create! :category => @c2 - @p4 = @a3.posts.create! :category => @c3 - @a1.reload - @a2.reload - end - - it "a1.posts should == [p1]" do - @a1.posts.should == [@p1] - end - - it "a1.categories should == [c1]" do - @a1.categories.should == [@c1] - end - - it "a2.posts should == [p2, p3]" do - @a2.posts.should == [@p2, @p3] - end - - it "a2.categories should == [c1, c2]" do - @a2.categories.should == [@c1, @c2] - end - - describe "u1 comments on p2" do - before do - @u1 = User.create! - @comment = @p2.comments.create! :user => @u1 - end - - it "u1.comments should == [comment]" do - @u1.comments.should == [@comment] - end - - it "a1.commenters should be empty" do - @a1.commenters.should be_empty - end - - it "a2.commenters should == [u1]" do - @a2.commenters.should == [@u1] - end - - it "u1.commented_posts should == [p2]" do - @u1.commented_posts.should == [@p2] - end - - it "u1.commented_posts.find_inflamatory(:all) should be empty" do - @u1.commented_posts.find_inflamatory(:all).should be_empty - end - - if ActiveRecord::Base.respond_to?(:named_scope) - it "u1.commented_posts.inflamatory should be empty" do - @u1.commented_posts.inflamatory.should be_empty - end - end - - it "u1.commented_authors should == [a2]" do - @u1.commented_authors.should == [@a2] - end - - it "u1.posts_of_interest should == [p1, p2, p3]" do - @u1.posts_of_interest.should == [@p1, @p2, @p3] - end - - it "u1.categories_of_interest should == [c1, c2]" do - @u1.categories_of_interest.should == [@c1, @c2] - end - - describe "when p2 is inflamatory" do - before do - @p2.toggle!(:inflamatory) - end - - it "p2 should be inflamatory" do - @p2.should be_inflamatory - end - - it "u1.commented_posts.find_inflamatory(:all) should == [p2]" do - # uniq ids is here (and next spec) because eager loading changed behaviour 2.0.2 => edge - @u1.commented_posts.find_inflamatory(:all).collect(&:id).uniq.should == [@p2.id] - end - - it "u1.posts_of_interest.find_inflamatory(:all).uniq should == [p2]" do - @u1.posts_of_interest.find_inflamatory(:all).collect(&:id).uniq.should == [@p2.id] - end - - if ActiveRecord::Base.respond_to?(:named_scope) - it "u1.commented_posts.inflamatory should == [p2]" do - @u1.commented_posts.inflamatory.should == [@p2] - end - - it "u1.posts_of_interest.inflamatory should == [p2]" do - @u1.posts_of_interest.inflamatory.should == [@p2] - end - end - end - end -end diff --git a/vendor/plugins/nested_has_many_through/spec/spec_helper.rb b/vendor/plugins/nested_has_many_through/spec/spec_helper.rb deleted file mode 100644 index 6ef8611..0000000 --- a/vendor/plugins/nested_has_many_through/spec/spec_helper.rb +++ /dev/null @@ -1,23 +0,0 @@ -# This file is copied to ~/spec when you run 'ruby script/generate rspec' -# from the project root directory. -ENV["RAILS_ENV"] ||= "test" -require File.expand_path(File.join(File.dirname(__FILE__), "../../../../config/environment")) -require 'spec/rails' - -Spec::Runner.configure do |config| - config.use_transactional_fixtures = true - config.use_instantiated_fixtures = false - config.fixture_path = Rails.root + '/spec/fixtures' - - # You can declare fixtures for each behaviour like this: - # describe "...." do - # fixtures :table_a, :table_b - # - # Alternatively, if you prefer to declare them only once, you can - # do so here, like so ... - # - # config.global_fixtures = :table_a, :table_b - # - # If you declare global fixtures, be aware that they will be declared - # for all of your examples, even those that don't use them. -end \ No newline at end of file diff --git a/vendor/plugins/xss_terminate/lib/xss_terminate.rb b/vendor/plugins/xss_terminate/lib/xss_terminate.rb index c373706..bd474cb 100644 --- a/vendor/plugins/xss_terminate/lib/xss_terminate.rb +++ b/vendor/plugins/xss_terminate/lib/xss_terminate.rb @@ -26,11 +26,11 @@ module XssTerminate else before_save filter_with end - write_inheritable_attribute("xss_terminate_#{options[:with]}_options".to_sym, { + class_attribute "xss_terminate_#{options[:with]}_options".to_sym + self.send("xss_terminate_#{options[:with]}_options=".to_sym, { :except => (options[:except] || []), :only => (options[:only] || options[:sanitize] || []) }) - class_inheritable_reader "xss_terminate_#{options[:with]}_options".to_sym include XssTerminate::InstanceMethods end -- libgit2 0.21.2