muck-activities 0.1.16 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/.gitignore +2 -1
  2. data/VERSION +1 -1
  3. data/app/controllers/muck/activities_controller.rb +12 -6
  4. data/app/helpers/muck_activity_helper.rb +21 -6
  5. data/app/views/activities/_comment.html.erb +4 -4
  6. data/app/views/activities/_current_status.html.erb +1 -1
  7. data/app/views/activity_templates/_generic.html.erb +4 -2
  8. data/app/views/activity_templates/_status_update.html.erb +3 -1
  9. data/db/migrate/20090730044139_add_comment_cache.rb +9 -0
  10. data/lib/active_record/acts/muck_activity.rb +2 -2
  11. data/lib/muck_activities/muck_activity_sources.rb +15 -0
  12. data/locales/en.yml +0 -1
  13. data/muck-activities.gemspec +16 -3
  14. data/test/rails_root/Rakefile +2 -1
  15. data/test/rails_root/app/models/share.rb +3 -0
  16. data/test/rails_root/app/models/user.rb +1 -0
  17. data/test/rails_root/config/database.yml +4 -1
  18. data/test/rails_root/config/environment.rb +1 -0
  19. data/test/rails_root/config/environments/cucumber.rb +21 -0
  20. data/test/rails_root/db/migrate/20090730044139_add_comment_cache.rb +9 -0
  21. data/test/rails_root/db/migrate/20090803185323_create_shares.rb +16 -0
  22. data/test/rails_root/db/schema.rb +13 -1
  23. data/test/rails_root/features/step_definitions/webrat_steps.rb +53 -23
  24. data/test/rails_root/features/support/env.rb +14 -3
  25. data/test/rails_root/features/support/paths.rb +27 -0
  26. data/test/rails_root/lib/tasks/cucumber.rake +20 -0
  27. data/test/rails_root/script/cucumber +2 -1
  28. data/test/rails_root/test/factories.rb +15 -1
  29. data/test/rails_root/test/functional/activities_controller_test.rb +17 -1
  30. data/test/rails_root/test/unit/activity_test.rb +26 -0
  31. data/test/rails_root/test/unit/share_test.rb +19 -0
  32. metadata +16 -3
  33. data/app/views/activities/_delete.html.erb +0 -11
data/.gitignore CHANGED
@@ -2,4 +2,5 @@
2
2
  .DS_Store
3
3
  coverage
4
4
  rdoc
5
- pkg
5
+ pkg
6
+ log/*
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.16
1
+ 0.1.17
@@ -4,18 +4,18 @@ class Muck::ActivitiesController < ApplicationController
4
4
  include ApplicationHelper
5
5
  include MuckActivityHelper
6
6
 
7
- before_filter :login_required
7
+ before_filter :login_required, :except => :index
8
8
  before_filter :find_parent, :only => [:index, :create]
9
9
  before_filter :get_activity, :only => [:destroy, :comment_html]
10
10
 
11
11
  def index
12
12
  if @parent.can_view?(current_user)
13
13
  @activities = get_activities(@parent)
14
- respond_to do |format|
15
- format.js do
16
- render :partial => "activities/cached_activities", :locals => {:activities => @activities}
17
- end
18
- end
14
+ else
15
+ @activities = get_profile_activities(@parent) # only items for the profile
16
+ end
17
+ respond_to do |format|
18
+ format.js { render :text => get_activities_html(@activities) }
19
19
  end
20
20
  end
21
21
 
@@ -128,6 +128,12 @@ class Muck::ActivitiesController < ApplicationController
128
128
 
129
129
  protected
130
130
 
131
+ def get_activities_html(activities)
132
+ render_as_html do
133
+ render_to_string(:partial => "activities/cached_activities", :locals => {:activities => @activities})
134
+ end
135
+ end
136
+
131
137
  def get_status_html(activity)
132
138
  render_as_html do
133
139
  render_to_string(:partial => 'activities/current_status', :locals => {:activities_object => activity})
@@ -6,7 +6,7 @@ module MuckActivityHelper
6
6
 
7
7
  def activity_comment_link(activity, comment = nil)
8
8
  if GlobalConfig.enable_activity_comments
9
- comment_form(activity, comment = nil)
9
+ comment_form(activity, comment)
10
10
  end
11
11
  end
12
12
 
@@ -20,7 +20,7 @@ module MuckActivityHelper
20
20
 
21
21
  # Renders an activity with only activities created by activities_object
22
22
  def limited_activity_feed_for(activities_object)
23
- activities = activities_object.activities.created_by(activities_object).find(:all, :include => ['comments']).paginate(:page => @page, :per_page => @per_page)
23
+ activities = activities_object.activities.created_by(activities_object).only_public.find(:all, :include => ['comments']).paginate(:page => @page, :per_page => @per_page)
24
24
  render :partial => 'activities/activity_feed', :locals => { :activities_object => activities_object, :activities => activities }
25
25
  end
26
26
 
@@ -42,7 +42,7 @@ module MuckActivityHelper
42
42
 
43
43
  # Renders a delete button for an activity
44
44
  def delete_activity(activity, button_type = :button, button_text = t("muck.activities.clear"))
45
- render :partial => 'activities/delete', :locals => { :delete_object => activity,
45
+ render :partial => 'shared/delete', :locals => { :delete_object => activity,
46
46
  :button_type => button_type,
47
47
  :button_text => button_text,
48
48
  :form_class => 'activity-delete',
@@ -50,8 +50,8 @@ module MuckActivityHelper
50
50
  end
51
51
 
52
52
  # Renders a delete button for a comment inside an activity feed
53
- def delete_comment(comment, button_type = :button, button_text = t("muck.activities.delete"))
54
- render :partial => 'activities/delete', :locals => { :delete_object => comment,
53
+ def delete_activity_comment(comment, button_type = :button, button_text = t("muck.activities.delete"))
54
+ render :partial => 'shared/delete', :locals => { :delete_object => comment,
55
55
  :button_type => button_type,
56
56
  :button_text => button_text,
57
57
  :form_class => 'comment-delete',
@@ -83,6 +83,14 @@ module MuckActivityHelper
83
83
  request.url.gsub(request.query_string, '')
84
84
  end
85
85
 
86
+ def get_profile_activities(activities_object)
87
+ if !params[:latest_activity_id].blank?
88
+ activities_object.activities.filter_by_template(params[:activity_filter]).after(params[:latest_activity_id]).only_public.created_by(activities_object).find(:all, :include => ['comments']).paginate(:page => @page, :per_page => @per_page)
89
+ else
90
+ activities_object.activities.filter_by_template(params[:activity_filter]).only_public.created_by(activities_object).find(:all, :include => ['comments']).paginate(:page => @page, :per_page => @per_page)
91
+ end
92
+ end
93
+
86
94
  def get_activities(activities_object)
87
95
  if !params[:latest_activity_id].blank?
88
96
  activities_object.activities.filter_by_template(params[:activity_filter]).after(params[:latest_activity_id]).find(:all, :include => ['comments']).paginate(:page => @page, :per_page => @per_page)
@@ -90,5 +98,12 @@ module MuckActivityHelper
90
98
  activities_object.activities.filter_by_template(params[:activity_filter]).find(:all, :include => ['comments']).paginate(:page => @page, :per_page => @per_page)
91
99
  end
92
100
  end
93
-
101
+
102
+ # Render an activity using a block and the given activity.
103
+ # options:
104
+ # activity_css_class - css class to attach to the given activity
105
+ def activity_for(activity, options = {}, &block)
106
+ block_to_partial('activity_templates/generic', options.merge(:activity => activity), &block)
107
+ end
108
+
94
109
  end
@@ -1,7 +1,7 @@
1
1
  <div id="<%= comment.dom_id %>" class="activity-comment delete-container">
2
- <div class="actor-icon"><%= icon comment_owner.source %></div>
3
- <%= delete_comment(comment, :image) if comment.can_edit?(current_user) %>
4
- <p><span class="actor"><%= link_to comment_owner.source.display_name, comment_owner.source %></span>
5
- <span class="activity-time"><%= t("muck.activities.time_ago", :time_in_words => time_ago_in_words(comment_owner.created_at)) %></span></p>
2
+ <div class="actor-icon"><%= icon(comment.user) %></div>
3
+ <%= delete_activity_comment(comment, :image) if comment.can_edit?(current_user) %>
4
+ <p><span class="actor"><%= link_to comment.user.display_name, comment.user %></span>
5
+ <span class="activity-time"><%= t("muck.general.time_ago", :time_in_words => time_ago_in_words(comment_owner.created_at)) %></span></p>
6
6
  <p><%= h comment.body %></p>
7
7
  </div>
@@ -6,7 +6,7 @@ else
6
6
  time = false
7
7
  end -%>
8
8
  <p id="current-status-text"><span id="current-status-name"><%= activities_object.display_name %></span> <%= status %></p>
9
- <span id="status-time" class="status-time"><%= t('muck.activities.time_ago', :time_in_words => time_ago_in_words(time)) if time %></span>
9
+ <span id="status-time" class="status-time"><%= t('muck.general.time_ago', :time_in_words => time_ago_in_words(time)) if time %></span>
10
10
  <span id="status-clear">
11
11
  <% if activities_object.status -%>
12
12
  - <%= delete_activity(activities_object.status, :text, t("muck.activities.clear")) %>
@@ -1,9 +1,11 @@
1
1
  <div class="activity <%= activity_css_class %> delete-container" id="<%= activity.dom_id %>">
2
2
  <div class="actor-icon"><%= icon activity.source %></div>
3
3
  <div class="activity-content">
4
- <p><span class="actor"><%= link_to activity.source.display_name, activity.source %></span> <%= activity.content %></p>
4
+ <p><span class="actor"><%= link_to activity.source.display_name, activity.source %></span>
5
+ <%= body %>
6
+ </p>
5
7
  <%= delete_activity(activity, :image) %>
6
- <span class="activity-time"><%= t("muck.activities.time_ago", :time_in_words => time_ago_in_words(activity.created_at)) %></span>
8
+ <span class="activity-time"><%= t("muck.general.time_ago", :time_in_words => time_ago_in_words(activity.created_at)) %></span>
7
9
  <% if !activity.has_comments? -%>
8
10
  <span><a id="make_comment_<%=activity.dom_id%>" class="make-comment" href="#"><%=t('muck.activities.make_comment')%></a></span>
9
11
  <% end -%>
@@ -1 +1,3 @@
1
- <%= render :partial => 'activity_templates/generic', :locals => { :activity => activity, :activity_css_class => 'activity-status-update' } %>
1
+ <% activity_for(activity, :activity_css_class => 'activity-status-update') do %>
2
+ <%= activity.content %>
3
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ class AddCommentCache < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :activities, :comment_count, :integer, :default => 0
4
+ end
5
+
6
+ def self.down
7
+ remove_column :activities, :comment_count
8
+ end
9
+ end
@@ -11,7 +11,7 @@ module ActiveRecord
11
11
 
12
12
  belongs_to :item, :polymorphic => true
13
13
  belongs_to :source, :polymorphic => true
14
- has_many :activity_feeds
14
+ has_many :activity_feeds, :dependent => :destroy
15
15
 
16
16
  acts_as_commentable
17
17
 
@@ -21,7 +21,7 @@ module ActiveRecord
21
21
  named_scope :before, lambda { |time| {:conditions => ["activities.created_at < ?", time || DateTime.now] } }
22
22
  named_scope :newest, :order => "activities.created_at DESC"
23
23
  named_scope :after, lambda { |id| {:conditions => ["activities.id > ?", id] } }
24
- named_scope :only_public, :conditions => ["activities.is_public = true"]
24
+ named_scope :only_public, :conditions => ["activities.is_public = ?", true]
25
25
  named_scope :filter_by_template, lambda { |template| { :conditions => ["activities.template = ?", template] } unless template.blank? }
26
26
  named_scope :created_by, lambda { |activity_object| {:conditions => ["activities.source_id = ? AND activities.source_type = ?", activity_object.id, activity_object.class.to_s] } }
27
27
  named_scope :status_updates, :conditions => ["activities.is_status_update = ?", true]
@@ -26,6 +26,21 @@ module MuckActivitySources # :nodoc:
26
26
  end
27
27
  end
28
28
 
29
+ # +acts_as_activity_item+ gives the class it is called on a method called
30
+ # +add_activity+ that can add activities into a feed.
31
+ # It also setups up the object to be an 'item' in the activity feed.
32
+ # For example if you have a model called 'friend' which serves as an object
33
+ # that will be used as an 'item' in an activity feed, calling acts_as_activity_item
34
+ # will add 'activities' to the friend object so that you can call @friend.activities to
35
+ # retrieve all the activities for which the @friend object is an item. Deleting the @friend
36
+ # object will destroy all related activites.
37
+ def acts_as_activity_item
38
+ has_many :activities, :as => :item, :dependent => :destroy
39
+ unless included_modules.include? InstanceMethods
40
+ include InstanceMethods
41
+ end
42
+ end
43
+
29
44
  end
30
45
 
31
46
  module InstanceMethods
data/locales/en.yml CHANGED
@@ -18,7 +18,6 @@ en:
18
18
  problem_with_status: "There was a problem changing your status"
19
19
  update_error: "Oops... There was a problem. {{errors}}"
20
20
  update_status_message: "update your status!"
21
- time_ago: "{{time_in_words}} ago"
22
21
  template_or_item_required: "An activity requires a template or an item to display correctly"
23
22
  paging_newer: "&laquo; Newer"
24
23
  paging_older: "Older &raquo;"
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{muck-activities}
5
- s.version = "0.1.16"
5
+ s.version = "0.1.17"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Justin Ball"]
9
- s.date = %q{2009-07-24}
9
+ s.date = %q{2009-08-08}
10
10
  s.description = %q{Activity engine for the muck system.}
11
11
  s.email = %q{justinball@gmail.com}
12
12
  s.extra_rdoc_files = [
@@ -27,13 +27,13 @@ Gem::Specification.new do |s|
27
27
  "app/views/activities/_comments.html.erb",
28
28
  "app/views/activities/_current_status.html.erb",
29
29
  "app/views/activities/_current_status_wrapper.html.erb",
30
- "app/views/activities/_delete.html.erb",
31
30
  "app/views/activities/_status_update.html.erb",
32
31
  "app/views/activities/_template_filter.html.erb",
33
32
  "app/views/activity_templates/_generic.html.erb",
34
33
  "app/views/activity_templates/_status_update.html.erb",
35
34
  "config/muck_activities_routes.rb",
36
35
  "db/migrate/20090402033319_add_muck_activities.rb",
36
+ "db/migrate/20090730044139_add_comment_cache.rb",
37
37
  "install.rb",
38
38
  "lib/active_record/acts/muck_activity.rb",
39
39
  "lib/muck_activities.rb",
@@ -101,6 +101,7 @@ Gem::Specification.new do |s|
101
101
  "test/rails_root/app/models/activity.rb",
102
102
  "test/rails_root/app/models/comment.rb",
103
103
  "test/rails_root/app/models/profile.rb",
104
+ "test/rails_root/app/models/share.rb",
104
105
  "test/rails_root/app/models/user.rb",
105
106
  "test/rails_root/app/models/user_session.rb",
106
107
  "test/rails_root/app/views/default/index.html.erb",
@@ -109,6 +110,7 @@ Gem::Specification.new do |s|
109
110
  "test/rails_root/config/boot.rb",
110
111
  "test/rails_root/config/database.yml",
111
112
  "test/rails_root/config/environment.rb",
113
+ "test/rails_root/config/environments/cucumber.rb",
112
114
  "test/rails_root/config/environments/development.rb",
113
115
  "test/rails_root/config/environments/production.rb",
114
116
  "test/rails_root/config/environments/test.rb",
@@ -127,8 +129,12 @@ Gem::Specification.new do |s|
127
129
  "test/rails_root/db/migrate/20090512013727_create_profiles.rb",
128
130
  "test/rails_root/db/migrate/20090602041838_create_users.rb",
129
131
  "test/rails_root/db/migrate/20090613173314_create_comments.rb",
132
+ "test/rails_root/db/migrate/20090730044139_add_comment_cache.rb",
133
+ "test/rails_root/db/migrate/20090803185323_create_shares.rb",
130
134
  "test/rails_root/features/step_definitions/webrat_steps.rb",
131
135
  "test/rails_root/features/support/env.rb",
136
+ "test/rails_root/features/support/paths.rb",
137
+ "test/rails_root/lib/tasks/cucumber.rake",
132
138
  "test/rails_root/public/.htaccess",
133
139
  "test/rails_root/public/404.html",
134
140
  "test/rails_root/public/422.html",
@@ -296,6 +302,7 @@ Gem::Specification.new do |s|
296
302
  "test/rails_root/test/unit/.keep",
297
303
  "test/rails_root/test/unit/activity_feed_test.rb",
298
304
  "test/rails_root/test/unit/activity_test.rb",
305
+ "test/rails_root/test/unit/share_test.rb",
299
306
  "test/rails_root/test/unit/user_test.rb",
300
307
  "uninstall.rb"
301
308
  ]
@@ -313,10 +320,12 @@ Gem::Specification.new do |s|
313
320
  "test/rails_root/app/models/activity.rb",
314
321
  "test/rails_root/app/models/comment.rb",
315
322
  "test/rails_root/app/models/profile.rb",
323
+ "test/rails_root/app/models/share.rb",
316
324
  "test/rails_root/app/models/user.rb",
317
325
  "test/rails_root/app/models/user_session.rb",
318
326
  "test/rails_root/config/boot.rb",
319
327
  "test/rails_root/config/environment.rb",
328
+ "test/rails_root/config/environments/cucumber.rb",
320
329
  "test/rails_root/config/environments/development.rb",
321
330
  "test/rails_root/config/environments/production.rb",
322
331
  "test/rails_root/config/environments/test.rb",
@@ -333,9 +342,12 @@ Gem::Specification.new do |s|
333
342
  "test/rails_root/db/migrate/20090512013727_create_profiles.rb",
334
343
  "test/rails_root/db/migrate/20090602041838_create_users.rb",
335
344
  "test/rails_root/db/migrate/20090613173314_create_comments.rb",
345
+ "test/rails_root/db/migrate/20090730044139_add_comment_cache.rb",
346
+ "test/rails_root/db/migrate/20090803185323_create_shares.rb",
336
347
  "test/rails_root/db/schema.rb",
337
348
  "test/rails_root/features/step_definitions/webrat_steps.rb",
338
349
  "test/rails_root/features/support/env.rb",
350
+ "test/rails_root/features/support/paths.rb",
339
351
  "test/rails_root/public/dispatch.rb",
340
352
  "test/rails_root/script/create_project.rb",
341
353
  "test/rails_root/test/factories.rb",
@@ -345,6 +357,7 @@ Gem::Specification.new do |s|
345
357
  "test/rails_root/test/test_helper.rb",
346
358
  "test/rails_root/test/unit/activity_feed_test.rb",
347
359
  "test/rails_root/test/unit/activity_test.rb",
360
+ "test/rails_root/test/unit/share_test.rb",
348
361
  "test/rails_root/test/unit/user_test.rb"
349
362
  ]
350
363
 
@@ -13,4 +13,5 @@ require 'muck_engine/tasks'
13
13
  require 'muck_users/tasks'
14
14
  require 'muck_comments/tasks'
15
15
  require 'muck_activities/tasks'
16
- require 'muck_profiles/tasks'
16
+ require 'muck_profiles/tasks'
17
+ require 'muck_shares/tasks'
@@ -0,0 +1,3 @@
1
+ class Share < ActiveRecord::Base
2
+ acts_as_muck_share
3
+ end
@@ -5,6 +5,7 @@ class User < ActiveRecord::Base
5
5
  acts_as_muck_user
6
6
  has_muck_profile
7
7
  has_activities
8
+ acts_as_muck_sharer
8
9
 
9
10
  def feed_to
10
11
  [self]
@@ -3,7 +3,7 @@ development:
3
3
  database: db/development.sqlite3
4
4
  timeout: 5000
5
5
 
6
- test:
6
+ test: &TEST
7
7
  adapter: sqlite3
8
8
  database: db/test.sqlite3
9
9
  timeout: 5000
@@ -12,3 +12,6 @@ production:
12
12
  adapter: sqlite3
13
13
  database: db/production.sqlite3
14
14
  timeout: 5000
15
+
16
+ cucumber:
17
+ <<: *TEST
@@ -25,5 +25,6 @@ Rails::Initializer.run do |config|
25
25
  config.gem 'muck-users', :lib => 'muck_users'
26
26
  config.gem 'muck-comments', :lib => 'muck_comments'
27
27
  config.gem 'muck-profiles', :lib => 'muck_profiles'
28
+ config.gem 'muck-shares', :lib => 'muck_shares'
28
29
  config.plugin_locators << TestGemLocator
29
30
  end
@@ -0,0 +1,21 @@
1
+ config.cache_classes = true # This must be true for Cucumber to operate correctly!
2
+
3
+ # Log error messages when you accidentally call methods on nil.
4
+ config.whiny_nils = true
5
+
6
+ # Show full error reports and disable caching
7
+ config.action_controller.consider_all_requests_local = true
8
+ config.action_controller.perform_caching = false
9
+
10
+ # Disable request forgery protection in test environment
11
+ config.action_controller.allow_forgery_protection = false
12
+
13
+ # Tell Action Mailer not to deliver emails to the real world.
14
+ # The :test delivery method accumulates sent emails in the
15
+ # ActionMailer::Base.deliveries array.
16
+ config.action_mailer.delivery_method = :test
17
+
18
+ config.gem "cucumber", :lib => false, :version => ">=0.3.92" unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
19
+ config.gem "webrat", :lib => false, :version => ">=0.4.4" unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
20
+ config.gem "rspec", :lib => false, :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
21
+ config.gem "rspec-rails", :lib => 'spec/rails', :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
@@ -0,0 +1,9 @@
1
+ class AddCommentCache < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :activities, :comment_count, :integer, :default => 0
4
+ end
5
+
6
+ def self.down
7
+ remove_column :activities, :comment_count
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ class CreateShares < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :shares, :force => true do |t|
4
+ t.string :uri, :limit => 2083, :default => "", :null => false
5
+ t.string :title
6
+ t.text :message
7
+ t.integer :shared_by_id, :null => false
8
+ t.timestamps
9
+ end
10
+ add_index :shares, :shared_by_id
11
+ end
12
+
13
+ def self.down
14
+ drop_table :shares
15
+ end
16
+ end
@@ -9,7 +9,7 @@
9
9
  #
10
10
  # It's strongly recommended to check this file into your version control system.
11
11
 
12
- ActiveRecord::Schema.define(:version => 20090613173314) do
12
+ ActiveRecord::Schema.define(:version => 20090803185323) do
13
13
 
14
14
  create_table "activities", :force => true do |t|
15
15
  t.integer "item_id"
@@ -23,6 +23,7 @@ ActiveRecord::Schema.define(:version => 20090613173314) do
23
23
  t.boolean "is_public", :default => true
24
24
  t.datetime "created_at"
25
25
  t.datetime "updated_at"
26
+ t.integer "comment_count", :default => 0
26
27
  end
27
28
 
28
29
  add_index "activities", ["item_id", "item_type"], :name => "index_activities_on_item_id_and_item_type"
@@ -97,6 +98,17 @@ ActiveRecord::Schema.define(:version => 20090613173314) do
97
98
  t.datetime "updated_at"
98
99
  end
99
100
 
101
+ create_table "shares", :force => true do |t|
102
+ t.string "uri", :limit => 2083, :default => "", :null => false
103
+ t.string "title"
104
+ t.text "message"
105
+ t.integer "shared_by_id", :null => false
106
+ t.datetime "created_at"
107
+ t.datetime "updated_at"
108
+ end
109
+
110
+ add_index "shares", ["shared_by_id"], :name => "index_shares_on_shared_by_id"
111
+
100
112
  create_table "states", :force => true do |t|
101
113
  t.string "name", :limit => 128, :default => "", :null => false
102
114
  t.string "abbreviation", :limit => 3, :default => "", :null => false
@@ -3,29 +3,33 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "pat
3
3
  # Commonly used webrat steps
4
4
  # http://github.com/brynary/webrat
5
5
 
6
+ Given /^I am on (.+)$/ do |page_name|
7
+ visit path_to(page_name)
8
+ end
9
+
6
10
  When /^I go to (.+)$/ do |page_name|
7
11
  visit path_to(page_name)
8
12
  end
9
13
 
10
- When /^I press "(.*)"$/ do |button|
14
+ When /^I press "([^\"]*)"$/ do |button|
11
15
  click_button(button)
12
16
  end
13
17
 
14
- When /^I follow "(.*)"$/ do |link|
18
+ When /^I follow "([^\"]*)"$/ do |link|
15
19
  click_link(link)
16
20
  end
17
21
 
18
- When /^I fill in "(.*)" with "(.*)"$/ do |field, value|
22
+ When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
19
23
  fill_in(field, :with => value)
20
24
  end
21
25
 
22
- When /^I select "(.*)" from "(.*)"$/ do |value, field|
26
+ When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
23
27
  select(value, :from => field)
24
28
  end
25
29
 
26
30
  # Use this step in conjunction with Rail's datetime_select helper. For example:
27
31
  # When I select "December 25, 2008 10:00" as the date and time
28
- When /^I select "(.*)" as the date and time$/ do |time|
32
+ When /^I select "([^\"]*)" as the date and time$/ do |time|
29
33
  select_datetime(time)
30
34
  end
31
35
 
@@ -36,64 +40,90 @@ end
36
40
  # <%= f.label :alternative %><br />
37
41
  # <%= f.datetime_select :alternative %>
38
42
  # The following steps would fill out the form:
39
- # When I select "November 23, 2004 11:20" as the "Preferred" data and time
40
- # And I select "November 25, 2004 10:30" as the "Alternative" data and time
41
- When /^I select "(.*)" as the "(.*)" date and time$/ do |datetime, datetime_label|
43
+ # When I select "November 23, 2004 11:20" as the "Preferred" date and time
44
+ # And I select "November 25, 2004 10:30" as the "Alternative" date and time
45
+ When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
42
46
  select_datetime(datetime, :from => datetime_label)
43
47
  end
44
48
 
45
- # Use this step in conjuction with Rail's time_select helper. For example:
49
+ # Use this step in conjunction with Rail's time_select helper. For example:
46
50
  # When I select "2:20PM" as the time
47
51
  # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
48
52
  # will convert the 2:20PM to 14:20 and then select it.
49
- When /^I select "(.*)" as the time$/ do |time|
53
+ When /^I select "([^\"]*)" as the time$/ do |time|
50
54
  select_time(time)
51
55
  end
52
56
 
53
57
  # Use this step when using multiple time_select helpers on a page or you want to
54
58
  # specify the name of the time on the form. For example:
55
59
  # When I select "7:30AM" as the "Gym" time
56
- When /^I select "(.*)" as the "(.*)" time$/ do |time, time_label|
60
+ When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
57
61
  select_time(time, :from => time_label)
58
62
  end
59
63
 
60
- # Use this step in conjuction with Rail's date_select helper. For example:
64
+ # Use this step in conjunction with Rail's date_select helper. For example:
61
65
  # When I select "February 20, 1981" as the date
62
- When /^I select "(.*)" as the date$/ do |date|
66
+ When /^I select "([^\"]*)" as the date$/ do |date|
63
67
  select_date(date)
64
68
  end
65
69
 
66
70
  # Use this step when using multiple date_select helpers on one page or
67
71
  # you want to specify the name of the date on the form. For example:
68
72
  # When I select "April 26, 1982" as the "Date of Birth" date
69
- When /^I select "(.*)" as the "(.*)" date$/ do |date, date_label|
73
+ When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
70
74
  select_date(date, :from => date_label)
71
75
  end
72
76
 
73
- When /^I check "(.*)"$/ do |field|
77
+ When /^I check "([^\"]*)"$/ do |field|
74
78
  check(field)
75
79
  end
76
80
 
77
- When /^I uncheck "(.*)"$/ do |field|
81
+ When /^I uncheck "([^\"]*)"$/ do |field|
78
82
  uncheck(field)
79
83
  end
80
84
 
81
- When /^I choose "(.*)"$/ do |field|
85
+ When /^I choose "([^\"]*)"$/ do |field|
82
86
  choose(field)
83
87
  end
84
88
 
85
- When /^I attach the file at "(.*)" to "(.*)" $/ do |path, field|
89
+ When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
86
90
  attach_file(field, path)
87
91
  end
88
92
 
89
- Then /^I should see "(.*)"$/ do |text|
90
- assert_match /#{text}/m, response.body
93
+ Then /^I should see "([^\"]*)"$/ do |text|
94
+ response.should contain(text)
95
+ end
96
+
97
+ Then /^I should see \/([^\/]*)\/$/ do |regexp|
98
+ regexp = Regexp.new(regexp)
99
+ response.should contain(regexp)
100
+ end
101
+
102
+ Then /^I should not see "([^\"]*)"$/ do |text|
103
+ response.should_not contain(text)
91
104
  end
92
105
 
93
- Then /^I should not see "(.*)"$/ do |text|
94
- assert_match /#{text}/m, response.body
106
+ Then /^I should not see \/([^\/]*)\/$/ do |regexp|
107
+ regexp = Regexp.new(regexp)
108
+ response.should_not contain(regexp)
95
109
  end
96
110
 
97
- Then /^the "(.*)" checkbox should be checked$/ do |label|
111
+ Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
112
+ field_labeled(field).value.should =~ /#{value}/
113
+ end
114
+
115
+ Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
116
+ field_labeled(field).value.should_not =~ /#{value}/
117
+ end
118
+
119
+ Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
98
120
  field_labeled(label).should be_checked
99
121
  end
122
+
123
+ Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
124
+ field_labeled(label).should_not be_checked
125
+ end
126
+
127
+ Then /^I should be on (.+)$/ do |page_name|
128
+ URI.parse(current_url).path.should == path_to(page_name)
129
+ end
@@ -1,14 +1,25 @@
1
1
  # Sets up the Rails environment for Cucumber
2
- ENV["RAILS_ENV"] = "test"
2
+ ENV["RAILS_ENV"] ||= "cucumber"
3
3
  require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
4
- require 'factory_girl'
5
4
  require 'cucumber/rails/world'
6
- require 'cucumber/formatter/unicode' # Comment out this line if you don't want Cucumber Unicode support
5
+
6
+ # Comment out the next line if you don't want Cucumber Unicode support
7
+ require 'cucumber/formatter/unicode'
8
+
9
+ # Comment out the next line if you don't want transactions to
10
+ # open/roll back around each scenario
7
11
  Cucumber::Rails.use_transactional_fixtures
12
+
13
+ # Comment out the next line if you want Rails' own error handling
14
+ # (e.g. rescue_action_in_public / rescue_responses / rescue_from)
8
15
  Cucumber::Rails.bypass_rescue
9
16
 
10
17
  require 'webrat'
18
+ require 'cucumber/webrat/table_locator' # Lets you do table.diff!(table_at('#my_table').to_a)
11
19
 
12
20
  Webrat.configure do |config|
13
21
  config.mode = :rails
14
22
  end
23
+
24
+ require 'cucumber/rails/rspec'
25
+ require 'webrat/core/matchers'
@@ -0,0 +1,27 @@
1
+ module NavigationHelpers
2
+ # Maps a name to a path. Used by the
3
+ #
4
+ # When /^I go to (.+)$/ do |page_name|
5
+ #
6
+ # step definition in webrat_steps.rb
7
+ #
8
+ def path_to(page_name)
9
+ case page_name
10
+
11
+ when /the homepage/
12
+ '/'
13
+
14
+ # Add more mappings here.
15
+ # Here is a more fancy example:
16
+ #
17
+ # when /^(.*)'s profile page$/i
18
+ # user_profile_path(User.find_by_login($1))
19
+
20
+ else
21
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
22
+ "Now, go and add a mapping in #{__FILE__}"
23
+ end
24
+ end
25
+ end
26
+
27
+ World(NavigationHelpers)
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib') if File.directory?(RAILS_ROOT + '/vendor/plugins/cucumber/lib')
2
+
3
+ unless ARGV.any? {|a| a =~ /^gems/}
4
+
5
+ begin
6
+ require 'cucumber/rake/task'
7
+
8
+ Cucumber::Rake::Task.new(:features) do |t|
9
+ t.fork = true
10
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
11
+ end
12
+ task :features => 'db:test:prepare'
13
+ rescue LoadError
14
+ desc 'Cucumber rake task not available'
15
+ task :features do
16
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
17
+ end
18
+ end
19
+
20
+ end
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  begin
3
3
  load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber")
4
- rescue LoadError
4
+ rescue LoadError => e
5
+ raise unless e.to_s =~ /cucumber/
5
6
  require "rubygems"
6
7
  load File.join(Gem.bindir, "cucumber")
7
8
  end
@@ -10,6 +10,10 @@ Factory.sequence :name do |n|
10
10
  "a_name#{n}"
11
11
  end
12
12
 
13
+ Factory.sequence :title do |n|
14
+ "a_title#{n}"
15
+ end
16
+
13
17
  Factory.sequence :abbr do |n|
14
18
  "abbr#{n}"
15
19
  end
@@ -43,4 +47,14 @@ end
43
47
  Factory.define :comment do |f|
44
48
  f.body 'test comment'
45
49
  f.user {|a| a.association(:user)}
46
- end
50
+ end
51
+
52
+ Factory.define :share do |f|
53
+ f.uri { Factory.next(:uri) }
54
+ f.title { Factory.next(:title) }
55
+ f.shared_by {|a| a.association(:user)}
56
+ end
57
+
58
+ Factory.sequence :uri do |n|
59
+ "n#{n}.example.com"
60
+ end
@@ -4,7 +4,23 @@ class Muck::ActivitiesControllerTest < ActionController::TestCase
4
4
 
5
5
  tests Muck::ActivitiesController
6
6
 
7
- context "activities controller" do
7
+ context "activities controller - anonymous" do
8
+ context "on GET to index" do
9
+ setup do
10
+ @user = Factory(:user)
11
+ @activity = Factory(:activity, :template => 'status_update')
12
+ @user.activities << @activity
13
+ end
14
+ context 'on GET to index (js)' do
15
+ setup do
16
+ get :index, :parent_type => @user.class, :parent_id => @user, :format => 'js', :latest_activity_id => @activity.to_param
17
+ end
18
+ should_respond_with :success
19
+ end
20
+ end
21
+ end
22
+
23
+ context "activities controller - logged in" do
8
24
  setup do
9
25
  activate_authlogic
10
26
  @user = Factory(:user)
@@ -23,6 +23,8 @@ class ActivityTest < ActiveSupport::TestCase
23
23
  @new_activity = Factory(:activity)
24
24
  @status_activity = Factory(:activity, :template => 'status')
25
25
  @other_activity = Factory(:activity, :template => 'other')
26
+ @private_activity = Factory(:activity, :is_public => false)
27
+ @public_activity = Factory(:activity, :is_public => true)
26
28
  end
27
29
  context "before" do
28
30
  should "only find old activity" do
@@ -45,6 +47,13 @@ class ActivityTest < ActiveSupport::TestCase
45
47
  assert !activities.include?(@other_activity), "since found other activity"
46
48
  end
47
49
  end
50
+ context "public" do
51
+ should "only find public activities" do
52
+ activities = Activity.only_public
53
+ assert activities.include?(@public_activity), "only_public didn't find public activity"
54
+ assert !activities.include?(@private_activity), "only_public found private activity"
55
+ end
56
+ end
48
57
  end
49
58
 
50
59
  should "require template or item" do
@@ -98,4 +107,21 @@ class ActivityTest < ActiveSupport::TestCase
98
107
 
99
108
  end
100
109
 
110
+ context "comments" do
111
+ setup do
112
+ @user = Factory(:user)
113
+ @activity = Factory(:activity)
114
+ @comment = @activity.comments.build(:body => 'a test comment')
115
+ @comment.user = @user
116
+ @comment.save!
117
+ end
118
+ should "have comments" do
119
+ assert_equal 1, @activity.comments.length
120
+ end
121
+ should "have comment cache" do
122
+ @activity.reload
123
+ assert_equal 1, @activity.comment_count
124
+ end
125
+ end
126
+
101
127
  end
@@ -0,0 +1,19 @@
1
+ # using muck shares to test acts_as_activity_item
2
+
3
+ require File.dirname(__FILE__) + '/../test_helper'
4
+
5
+ class ShareTest < ActiveSupport::TestCase
6
+ context "share" do
7
+ setup do
8
+ @user = Factory(:user)
9
+ @share = Factory(:share)
10
+ @share.add_share_activities([@user])
11
+ end
12
+ should_have_many :activities
13
+ should "delete activities if share is deleted" do
14
+ assert_difference "Activity.count", -1 do
15
+ @share.destroy
16
+ end
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muck-activities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Ball
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-24 00:00:00 -06:00
12
+ date: 2009-08-08 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -65,13 +65,13 @@ files:
65
65
  - app/views/activities/_comments.html.erb
66
66
  - app/views/activities/_current_status.html.erb
67
67
  - app/views/activities/_current_status_wrapper.html.erb
68
- - app/views/activities/_delete.html.erb
69
68
  - app/views/activities/_status_update.html.erb
70
69
  - app/views/activities/_template_filter.html.erb
71
70
  - app/views/activity_templates/_generic.html.erb
72
71
  - app/views/activity_templates/_status_update.html.erb
73
72
  - config/muck_activities_routes.rb
74
73
  - db/migrate/20090402033319_add_muck_activities.rb
74
+ - db/migrate/20090730044139_add_comment_cache.rb
75
75
  - install.rb
76
76
  - lib/active_record/acts/muck_activity.rb
77
77
  - lib/muck_activities.rb
@@ -139,6 +139,7 @@ files:
139
139
  - test/rails_root/app/models/activity.rb
140
140
  - test/rails_root/app/models/comment.rb
141
141
  - test/rails_root/app/models/profile.rb
142
+ - test/rails_root/app/models/share.rb
142
143
  - test/rails_root/app/models/user.rb
143
144
  - test/rails_root/app/models/user_session.rb
144
145
  - test/rails_root/app/views/default/index.html.erb
@@ -147,6 +148,7 @@ files:
147
148
  - test/rails_root/config/boot.rb
148
149
  - test/rails_root/config/database.yml
149
150
  - test/rails_root/config/environment.rb
151
+ - test/rails_root/config/environments/cucumber.rb
150
152
  - test/rails_root/config/environments/development.rb
151
153
  - test/rails_root/config/environments/production.rb
152
154
  - test/rails_root/config/environments/test.rb
@@ -165,8 +167,12 @@ files:
165
167
  - test/rails_root/db/migrate/20090512013727_create_profiles.rb
166
168
  - test/rails_root/db/migrate/20090602041838_create_users.rb
167
169
  - test/rails_root/db/migrate/20090613173314_create_comments.rb
170
+ - test/rails_root/db/migrate/20090730044139_add_comment_cache.rb
171
+ - test/rails_root/db/migrate/20090803185323_create_shares.rb
168
172
  - test/rails_root/features/step_definitions/webrat_steps.rb
169
173
  - test/rails_root/features/support/env.rb
174
+ - test/rails_root/features/support/paths.rb
175
+ - test/rails_root/lib/tasks/cucumber.rake
170
176
  - test/rails_root/public/.htaccess
171
177
  - test/rails_root/public/404.html
172
178
  - test/rails_root/public/422.html
@@ -334,6 +340,7 @@ files:
334
340
  - test/rails_root/test/unit/.keep
335
341
  - test/rails_root/test/unit/activity_feed_test.rb
336
342
  - test/rails_root/test/unit/activity_test.rb
343
+ - test/rails_root/test/unit/share_test.rb
337
344
  - test/rails_root/test/unit/user_test.rb
338
345
  - uninstall.rb
339
346
  has_rdoc: true
@@ -369,10 +376,12 @@ test_files:
369
376
  - test/rails_root/app/models/activity.rb
370
377
  - test/rails_root/app/models/comment.rb
371
378
  - test/rails_root/app/models/profile.rb
379
+ - test/rails_root/app/models/share.rb
372
380
  - test/rails_root/app/models/user.rb
373
381
  - test/rails_root/app/models/user_session.rb
374
382
  - test/rails_root/config/boot.rb
375
383
  - test/rails_root/config/environment.rb
384
+ - test/rails_root/config/environments/cucumber.rb
376
385
  - test/rails_root/config/environments/development.rb
377
386
  - test/rails_root/config/environments/production.rb
378
387
  - test/rails_root/config/environments/test.rb
@@ -389,9 +398,12 @@ test_files:
389
398
  - test/rails_root/db/migrate/20090512013727_create_profiles.rb
390
399
  - test/rails_root/db/migrate/20090602041838_create_users.rb
391
400
  - test/rails_root/db/migrate/20090613173314_create_comments.rb
401
+ - test/rails_root/db/migrate/20090730044139_add_comment_cache.rb
402
+ - test/rails_root/db/migrate/20090803185323_create_shares.rb
392
403
  - test/rails_root/db/schema.rb
393
404
  - test/rails_root/features/step_definitions/webrat_steps.rb
394
405
  - test/rails_root/features/support/env.rb
406
+ - test/rails_root/features/support/paths.rb
395
407
  - test/rails_root/public/dispatch.rb
396
408
  - test/rails_root/script/create_project.rb
397
409
  - test/rails_root/test/factories.rb
@@ -401,4 +413,5 @@ test_files:
401
413
  - test/rails_root/test/test_helper.rb
402
414
  - test/rails_root/test/unit/activity_feed_test.rb
403
415
  - test/rails_root/test/unit/activity_test.rb
416
+ - test/rails_root/test/unit/share_test.rb
404
417
  - test/rails_root/test/unit/user_test.rb
@@ -1,11 +0,0 @@
1
- <% if button_type == :text -%>
2
- <%= link_to_remote( button_text, :url => delete_path, :method => :delete) %>
3
- <% else -%>
4
- <% remote_form_for(delete_object, :url => delete_path, :html => { :class => "delete-form #{form_class}", :method => :delete } ) do |f| -%>
5
- <% if button_type == :image -%>
6
- <%= image_submit_tag '/images/icons/delete.png', {:title => button_text, :width => '15', :height => '15', :alt => button_text } %>
7
- <% else -%>
8
- <%= submit_tag button_text, { :title => button_text } %>
9
- <% end -%>
10
- <% end -%>
11
- <% end -%>