community_engine 2.3.1 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +6 -14
  2. data/.travis.yml +2 -2
  3. data/CHANGELOG +1 -0
  4. data/Gemfile +2 -0
  5. data/README.markdown +101 -57
  6. data/about.yml +1 -1
  7. data/app/controllers/authorizations_controller.rb +2 -1
  8. data/app/controllers/base_controller.rb +31 -43
  9. data/app/controllers/comments_controller.rb +11 -5
  10. data/app/controllers/messages_controller.rb +1 -1
  11. data/app/controllers/password_resets_controller.rb +4 -4
  12. data/app/controllers/sessions_controller.rb +3 -4
  13. data/app/helpers/base_helper.rb +47 -43
  14. data/app/models/album.rb +3 -3
  15. data/app/models/authorization.rb +14 -14
  16. data/app/models/clipping.rb +13 -13
  17. data/app/models/clipping_image.rb +4 -4
  18. data/app/models/comment.rb +18 -10
  19. data/app/models/event.rb +12 -12
  20. data/app/models/homepage_feature.rb +4 -4
  21. data/app/models/message.rb +2 -2
  22. data/app/models/metro_area.rb +1 -1
  23. data/app/models/photo.rb +4 -4
  24. data/app/models/poll.rb +1 -1
  25. data/app/models/post.rb +48 -48
  26. data/app/models/sb_post.rb +1 -1
  27. data/app/models/topic.rb +2 -2
  28. data/app/models/user.rb +3 -2
  29. data/app/views/admin/comments.html.haml +11 -8
  30. data/app/views/admin/users.html.haml +6 -4
  31. data/app/views/comments/_comment.html.haml +3 -0
  32. data/app/views/comments/approve.js.haml +1 -0
  33. data/app/views/layouts/application.html.haml +16 -16
  34. data/app/views/messages/_sent.html.haml +2 -2
  35. data/app/views/users/_search_options.html.haml +2 -2
  36. data/app/views/users/new.html.haml +4 -4
  37. data/community_engine.gemspec +4 -3
  38. data/config/locales/en.yml +10 -4
  39. data/config/routes.rb +35 -34
  40. data/db/migrate/090_add_comment_role.rb +15 -0
  41. data/lib/community_engine/authenticated_system.rb +11 -11
  42. data/lib/community_engine/engines_extensions.rb +14 -2
  43. data/lib/community_engine/version.rb +1 -1
  44. data/lib/tasks/community_engine_tasks.rake +3 -72
  45. data/test/functional/authorizations_controller_test.rb +60 -0
  46. data/test/functional/comments_controller_test.rb +44 -67
  47. data/test/functional/password_reset_controller_test.rb +14 -6
  48. data/test/functional/sessions_controller_test.rb +3 -3
  49. data/test/functional/topics_controller_test.rb +2 -2
  50. data/test/test_helper.rb +1 -8
  51. data/test/testapp/config/application.rb +4 -0
  52. data/test/testapp/db/schema.rb +4 -3
  53. data/test/unit/comment_test.rb +85 -28
  54. metadata +53 -49
  55. data/lib/community_engine/rails_asset_extensions.rb +0 -131
@@ -0,0 +1,15 @@
1
+ class AddCommentRole < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ add_column :comments, :role, :string, :default => 'comments'
5
+ end
6
+
7
+ def self.down
8
+ remove_column :comments, :role
9
+ end
10
+
11
+ end
12
+
13
+
14
+
15
+
@@ -1,19 +1,19 @@
1
1
  module AuthenticatedSystem
2
2
  def update_last_seen_at
3
3
  return unless logged_in?
4
- User.update_all ['sb_last_seen_at = ?', Time.now.utc], ['id = ?', current_user.id]
4
+ User.update_all ['sb_last_seen_at = ?', Time.now.utc], ['id = ?', current_user.id]
5
5
  current_user.sb_last_seen_at = Time.now.utc
6
6
  end
7
-
7
+
8
8
  def login_by_token
9
9
  end
10
-
10
+
11
11
  protected
12
12
  # Returns true or false if the user is logged in.
13
13
  def logged_in?
14
14
  current_user ? true : false
15
15
  end
16
-
16
+
17
17
  # Accesses the current user from the session.
18
18
  def current_user
19
19
  return @current_user if defined?(@current_user)
@@ -23,7 +23,7 @@ module AuthenticatedSystem
23
23
  # Create a user session without credentials.
24
24
  def current_user=(user)
25
25
  return if current_user # Use act_as_user= to switch to another user account
26
- @current_user_session = UserSession.create(user, true)
26
+ @current_user_session = UserSession.create(user)
27
27
  @current_user = @current_user_session.record
28
28
  end
29
29
 
@@ -76,9 +76,9 @@ module AuthenticatedSystem
76
76
  logged_in? && current_user.admin?
77
77
  end
78
78
  def moderator?
79
- logged_in? && current_user.moderator?
79
+ logged_in? && current_user.moderator?
80
80
  end
81
-
81
+
82
82
  # Redirect as appropriate when an access request fails.
83
83
  #
84
84
  # The default action is to redirect to the login screen.
@@ -99,19 +99,19 @@ module AuthenticatedSystem
99
99
  render :text => "Couldn't authenticate you", :status => '401 Unauthorized'
100
100
  end
101
101
  accepts.js do
102
- store_location
102
+ store_location
103
103
  render :update do |page|
104
104
  page.redirect_to login_path
105
105
  end and return false
106
- end
106
+ end
107
107
  end
108
108
  false
109
109
  end
110
-
110
+
111
111
  # Inclusion hook to make #current_user and #logged_in?
112
112
  # available as ActionView helper methods.
113
113
  def self.included(base)
114
- base.send :helper_method, :current_user, :current_user_session, :logged_in?, :admin?, :moderator?
114
+ base.send :helper_method, :current_user=, :current_user, :current_user_session, :logged_in?, :admin?, :moderator?
115
115
  end
116
116
 
117
117
  private
@@ -1,7 +1,19 @@
1
1
  module EnginesExtensions
2
2
 
3
3
  def require_from_ce(path)
4
- require_dependency CommunityEngine::Engine.config.root.join('app', path).to_s
4
+ require_dependency CommunityEngine::Engine.config.root.join('app', path).to_s
5
5
  end
6
-
6
+
7
+ def acts_as_moderated_commentable
8
+ acts_as_commentable :published, :pending
9
+ has_many :comments, {
10
+ :as => :commentable,
11
+ :dependent => :destroy,
12
+ :conditions => "role != 'pending'",
13
+ :before_add => Proc.new { |x, c| c.role = 'published' }
14
+ }
15
+ attr_protected :role
16
+ end
17
+
18
+
7
19
  end
@@ -2,7 +2,7 @@ module CommunityEngine
2
2
  module Version
3
3
  MAJOR = 2
4
4
  MINOR = 3
5
- PATCH = 1
5
+ PATCH = 2
6
6
  BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -1,7 +1,7 @@
1
1
  require 'rake/clean'
2
2
 
3
- namespace :community_engine do
4
-
3
+ namespace :community_engine do
4
+
5
5
  desc 'Assign admin role to user. Usage: rake community_engine:make_admin email=admin@foo.com'
6
6
  task :make_admin => :environment do
7
7
  email = ENV["email"]
@@ -14,74 +14,5 @@ namespace :community_engine do
14
14
  puts "There is no user with the e-mail '#{email}'."
15
15
  end
16
16
  end
17
-
18
- # desc 'Test the community_engine plugin.'
19
- # Rake::TestTask.new(:test) do |t|
20
- # t.libs << 'lib'
21
- # t.pattern = 'vendor/plugins/community_engine/test/**/*_test.rb'
22
- # t.verbose = true
23
- # end
24
- # Rake::Task['community_engine:test'].comment = "Run the community_engine plugin tests."
25
-
26
- # namespace :db do
27
- # namespace :fixtures do
28
- # desc "Load community engine fixtures"
29
- # task :load => :environment do
30
- # require 'active_record/fixtures'
31
- # ActiveRecord::Base.establish_connection(Rails.env.to_sym)
32
- # Dir.glob(File.join(Rails.root, 'vendor', 'plugins', 'community_engine','test','fixtures', '*.{yml,csv}')).each do |fixture_file|
33
- # Fixtures.create_fixtures('vendor/plugins/community_engine/test/fixtures', File.basename(fixture_file, '.*'))
34
- # end
35
- # end
36
- # end
37
- # end
38
-
39
- # namespace :db do
40
- # namespace :migrate do
41
- #
42
- # desc 'For CE coming from version < 1.0.1 that stored plugin migration info in the normal Rails schema_migrations table. Move that info back into the plugin_schema_migrations table.'
43
- # task :upgrade_desert_plugin_migrations => :environment do
44
- # plugin_migration_table = Desert::PluginMigrations::Migrator.schema_migrations_table_name
45
- # schema_migration_table = ActiveRecord::Migrator.schema_migrations_table_name
46
- #
47
- # unless ActiveRecord::Base.connection.table_exists?(plugin_migration_table)
48
- # ActiveRecord::Migration.create_table(plugin_migration_table, :id => false) do |schema_migrations_table|
49
- # schema_migrations_table.column :version, :string, :null => false
50
- # schema_migrations_table.column :plugin_name, :string, :null => false
51
- # end
52
- # end
53
- #
54
- # def insert_new_version(plugin_name, version, table)
55
- # # Check if the row already exists for some reason - maybe run this task more than once.
56
- # return if ActiveRecord::Base.connection.select_rows("SELECT * FROM #{table} WHERE version = #{version} AND plugin_name = '#{plugin_name}'").size > 0
57
- #
58
- # puts "Inserting new version #{version} for plugin #{plugin_name} in #{table}."
59
- # ActiveRecord::Base.connection.insert("INSERT INTO #{table} (plugin_name, version) VALUES ('#{plugin_name}', #{version.to_i})")
60
- # end
61
- #
62
- # def remove_old_version(plugin_name, version, table)
63
- # puts "Removing old version #{version} for plugin #{plugin_name} in #{table}."
64
- # ActiveRecord::Base.connection.execute("DELETE FROM #{table} WHERE version = '#{version}-#{plugin_name}'")
65
- # end
66
- #
67
- # existing_migrations = ActiveRecord::Base.connection.select_rows("SELECT * FROM #{schema_migration_table}").uniq
68
- # migrations = {}
69
- # existing_migrations.flatten.each do |m|
70
- # plugin_version, plugin_name = m.split('-')
71
- # next if plugin_name.blank?
72
- # migrations[plugin_name] ||= []
73
- # migrations[plugin_name] << plugin_version
74
- # end
75
- #
76
- # migrations.each do |plugin_name, versions|
77
- # versions.each do |version|
78
- # insert_new_version(plugin_name, version, plugin_migration_table)
79
- # remove_old_version(plugin_name, version, schema_migration_table)
80
- # end
81
- # end
82
- #
83
- # end
84
- # end
85
- # end
86
17
 
87
- end
18
+ end
@@ -0,0 +1,60 @@
1
+ require 'test_helper'
2
+
3
+ class AuthorizationsControllerTest < ActionController::TestCase
4
+ fixtures :all
5
+
6
+ setup do
7
+ OmniAuth.config.test_mode = true
8
+ end
9
+
10
+
11
+
12
+ test 'should create new authorization and log in' do
13
+
14
+ set_ommniauth
15
+
16
+ get :create
17
+
18
+ user = UserSession.find.record
19
+ assert_redirected_to user_path(user)
20
+ end
21
+
22
+ test 'should find existing authorization and log in' do
23
+ quentin = users(:quentin)
24
+ Authorization.create_from_hash(auth_hash(quentin.email), quentin)
25
+ set_ommniauth(quentin.email)
26
+
27
+ get :create
28
+
29
+ assert_redirected_to user_path(quentin)
30
+ end
31
+
32
+ test 'should authorize existing logged-in user' do
33
+ quentin = users(:quentin)
34
+ login_as :quentin
35
+
36
+ set_ommniauth(quentin.email)
37
+
38
+ get :create
39
+
40
+ assert_redirected_to user_path(quentin)
41
+ end
42
+
43
+
44
+ def set_ommniauth(email='email@example.com')
45
+ OmniAuth.config.mock_auth[:facebook] = auth_hash(email)
46
+ request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
47
+ end
48
+
49
+ def auth_hash(email)
50
+ {
51
+ 'provider' => 'facebook',
52
+ "info" => {
53
+ 'nickname' => 'Omniauth-user',
54
+ 'email' => email
55
+ },
56
+ 'uid' => '123545'
57
+ }
58
+ end
59
+
60
+ end
@@ -2,60 +2,37 @@ require 'test_helper'
2
2
 
3
3
  class CommentsControllerTest < ActionController::TestCase
4
4
  fixtures :users, :photos, :posts, :comments, :roles
5
-
6
- def test_should_create_user_comment_with_notification
7
- login_as :aaron
8
- assert_difference Comment, :count, 1 do
9
- assert_difference ActionMailer::Base.deliveries, :length, 1 do
10
- create_user_comment
11
- end
12
- end
13
- assert_response :redirect
14
- end
15
-
16
- def test_should_create_user_comment_and_notify_previous_commenters
17
- login_as :dwr
18
- # aaron should get a notification, because he's being commented on
19
- # quentin should get one too, because he previously commented on the profile
20
- assert_difference ActionMailer::Base.deliveries, :length, 2 do
21
- create_user_comment(:user_id => users(:aaron).id)
22
- end
23
- end
24
5
 
25
- def test_should_create_user_comment_without_notification
26
- users(:quentin).notify_comments = false
27
- users(:quentin).save!
6
+ def test_should_create_user_comment
28
7
  login_as :aaron
29
8
  assert_difference Comment, :count, 1 do
30
- assert_no_difference ActionMailer::Base.deliveries, :length do
31
9
  create_user_comment
32
- end
33
10
  end
34
11
  assert_response :redirect
35
12
  end
36
-
13
+
37
14
  def test_should_fail_to_create_user_comment
38
15
  login_as :aaron
39
16
  assert_no_difference Comment, :count do
40
17
  create_user_comment(:comment => {:comment => nil})
41
- end
42
- assert_response :redirect
18
+ end
19
+ assert_response :redirect
43
20
  end
44
-
21
+
45
22
  def test_should_create_photo_comment
46
23
  login_as :aaron
47
24
  assert_difference Comment, :count, 1 do
48
25
  create_photo_comment
49
26
  end
50
- assert_response :redirect
27
+ assert_response :redirect
51
28
  end
52
-
29
+
53
30
  def test_should_fail_to_create_photo_comment
54
31
  login_as :aaron
55
32
  assert_no_difference Comment, :count do
56
33
  create_photo_comment(:comment => {:comment => nil})
57
- end
58
- assert_response :redirect
34
+ end
35
+ assert_response :redirect
59
36
  end
60
37
 
61
38
  def test_should_create_post_comment
@@ -63,41 +40,41 @@ class CommentsControllerTest < ActionController::TestCase
63
40
  assert_difference Comment, :count, 1 do
64
41
  create_post_comment
65
42
  end
66
- assert_response :redirect
43
+ assert_response :redirect
67
44
  end
68
-
45
+
69
46
  def test_should_destroy_post_comment
70
47
  login_as :quentin
71
48
  assert_difference Comment, :count, -1 do
72
49
  delete :destroy, :commentable_type => 'Post', :commentable_id => comments(:quentins_comment_on_his_own_post).commentable_id, :id => comments(:quentins_comment_on_his_own_post)
73
50
  end
74
51
  end
75
-
52
+
76
53
  def test_should_not_destroy_post_comment
77
54
  login_as :aaron
78
55
  assert_no_difference Comment, :count do
79
56
  delete :destroy, :commentable_type => 'Post', :commentable_id => comments(:quentins_comment_on_his_own_post).commentable_id, :id => comments(:quentins_comment_on_his_own_post)
80
57
  end
81
58
  end
82
-
59
+
83
60
  def test_should_fail_to_create_post_comment
84
61
  login_as :aaron
85
62
  assert_no_difference Comment, :count do
86
63
  create_post_comment(:comment => {:comment => nil})
87
- end
88
- assert_response :redirect
64
+ end
65
+ assert_response :redirect
89
66
  end
90
67
 
91
68
  def test_should_fail_to_create_comment
92
69
  login_as :aaron
93
- assert_raises(NameError) do
70
+ assert_raises(NameError) do
94
71
  create_post_comment(:commentable_type => 'unkown_commentable_type')
95
72
  end
96
73
  end
97
74
 
98
75
  def test_should_show_comments_index
99
76
  login_as :quentin
100
- get :index, :commentable_type => 'users', :commentable_id => users(:aaron).to_param
77
+ get :index, :commentable_type => 'users', :commentable_id => users(:aaron).to_param
101
78
  assert_response :success
102
79
  assert !assigns(:comments).empty?
103
80
  end
@@ -108,14 +85,14 @@ class CommentsControllerTest < ActionController::TestCase
108
85
  assert_response :success
109
86
  assert !assigns(:comments).empty?
110
87
  end
111
-
88
+
112
89
  def test_should_show_empty_comments_index
113
90
  login_as :aaron
114
- get :index, :commentable_type => 'users', :commentable_id => users(:quentin).to_param
91
+ get :index, :commentable_type => 'users', :commentable_id => users(:quentin).to_param
115
92
  assert_response :success
116
93
  assert assigns(:comments).empty?
117
94
  end
118
-
95
+
119
96
  def test_should_show_empty_comments_index_rss
120
97
  login_as :aaron
121
98
  get :index, :commentable_type => 'users', :commentable_id => users(:quentin).to_param, :format => 'rss'
@@ -125,41 +102,41 @@ class CommentsControllerTest < ActionController::TestCase
125
102
 
126
103
  def test_should_show_private_comments_index_if_logged_in
127
104
  login_as :quentin
128
- get :index, :commentable_type => 'users', :commentable_id => users(:privateuser).to_param
129
- assert !assigns(:comments).empty?
105
+ get :index, :commentable_type => 'users', :commentable_id => users(:privateuser).to_param
106
+ assert !assigns(:comments).empty?
130
107
  assert_response :success
131
108
  end
132
109
 
133
110
  def test_should_not_show_private_comments_index
134
- get :index, :commentable_type => 'users', :commentable_id => users(:privateuser).to_param
111
+ get :index, :commentable_type => 'users', :commentable_id => users(:privateuser).to_param
135
112
  assert_response :redirect
136
113
  end
137
-
114
+
138
115
  def test_should_show_comments_index_rss_if_logged_in
139
116
  login_as :quentin
140
117
  get :index, :commentable_type => 'users', :commentable_id => users(:aaron).to_param, :format => 'rss'
141
118
  assert !assigns(:comments).empty?
142
119
  assert_response :success
143
120
  end
144
-
121
+
145
122
  def test_should_unsubscribe_with_token
146
123
  configatron.allow_anonymous_commenting = true
147
124
  comment = Comment.create!(:comment => 'foo', :author_email => 'bar@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin), :commentable => users(:quentin), :notify_by_email => true)
148
125
  configatron.allow_anonymous_commenting = false
149
-
126
+
150
127
  get :unsubscribe, :commentable_type => comment.commentable_type, :commentable_id => comment.commentable_id, :id => comment.id, :token => comment.token_for('bar@foo.com'), :email => 'bar@foo.com'
151
128
  assert comment.reload.notify_by_email.eql?(false)
152
129
  end
153
-
130
+
154
131
  def test_should_not_unsubscribe_with_bad_token
155
132
  configatron.allow_anonymous_commenting = true
156
133
  comment = Comment.create!(:comment => 'foo', :author_email => 'bar@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin), :commentable => users(:quentin), :notify_by_email => true)
157
134
  configatron.allow_anonymous_commenting = false
158
-
159
- get :unsubscribe, :commentable_type => 'User', :commentable_id => users(:quentin).to_param, :id => comment.id, :token => 'badtokengoeshere'
160
- assert comment.reload.notify_by_email.eql?(true)
135
+
136
+ get :unsubscribe, :commentable_type => 'User', :commentable_id => users(:quentin).to_param, :id => comment.id, :token => 'badtokengoeshere'
137
+ assert comment.reload.notify_by_email.eql?(true)
161
138
  end
162
-
139
+
163
140
  def test_should_get_edit_js_as_admin
164
141
  login_as :admin
165
142
  get :edit, :id => comments(:quentins_comment_on_his_own_post), :format => 'js'
@@ -170,42 +147,42 @@ class CommentsControllerTest < ActionController::TestCase
170
147
  login_as :admin
171
148
  edited_text = 'edited the comment body'
172
149
  put :update, :id => comments(:quentins_comment_on_his_own_post), :comment => {:comment => edited_text}, :format => 'js'
173
-
150
+
174
151
  assert assigns(:comment).comment.eql?(edited_text)
175
152
  assert_response :success
176
153
  end
177
-
154
+
178
155
  def test_should_not_update_if_not_admin_or_moderator
179
156
  login_as :quentin
180
-
181
- edited_text = 'edited the comment body'
157
+
158
+ edited_text = 'edited the comment body'
182
159
  put :update, :id => comments(:quentins_comment_on_his_own_post), :comment => {:comment => edited_text}, :format => "js"
183
-
160
+
184
161
  assert_response :success #js redirect
185
162
  assert_not_equal(comments(:quentins_comment_on_his_own_post).comment, edited_text)
186
163
  end
187
164
 
188
165
 
189
-
166
+
190
167
  protected
191
-
168
+
192
169
  def create_user_comment(options = {})
193
- post :create, {:commentable_type => (options[:commentable_type] || "users"),
194
- :commentable_id => (options[:user_id] || users(:quentin).id),
170
+ post :create, {:commentable_type => (options[:commentable_type] || "users"),
171
+ :commentable_id => (options[:user_id] || users(:quentin).id),
195
172
  :comment => {:title => "test comment to quentin", :comment => "hey man, how are you?"}.merge(options[:comment] || {})
196
173
  }
197
174
  end
198
175
 
199
176
  def create_photo_comment(options = {})
200
- post :create, {:commentable_type => (options[:commentable_type] || "photos"),
201
- :commentable_id => (options[:photo_id] || photos(:library_pic).id),
177
+ post :create, {:commentable_type => (options[:commentable_type] || "photos"),
178
+ :commentable_id => (options[:photo_id] || photos(:library_pic).id),
202
179
  :comment => {:title => "test comment on a photo", :comment => "hey man, nice pic?"}.merge(options[:comment] || {})
203
180
  }
204
181
  end
205
182
 
206
183
  def create_post_comment(options = {})
207
- post :create, {:commentable_type => (options[:commentable_type] || "posts"),
208
- :commentable_id => (options[:post_id] || posts(:funny_post).id),
184
+ post :create, {:commentable_type => (options[:commentable_type] || "posts"),
185
+ :commentable_id => (options[:post_id] || posts(:funny_post).id),
209
186
  :comment => {:title => "test comment on a posts", :comment => "hey man, nice posts?"}.merge(options[:comment] || {})
210
187
  }
211
188
  end