Commit d4e63efe4c43835a2bcd7e8a9cfc283a11373ff6

Authored by Antonio Terceiro
1 parent 822d4f60

Migration to Rails 3: checkpoint

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