social_stream-base 0.11.2 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. data/LICENSE +1 -1
  2. data/README.rdoc +1 -1
  3. data/app/assets/stylesheets/header.css.scss +9 -7
  4. data/app/controllers/groups_controller.rb +3 -4
  5. data/app/controllers/settings_controller.rb +14 -3
  6. data/app/controllers/users_controller.rb +3 -4
  7. data/app/helpers/permissions_helper.rb +2 -1
  8. data/app/models/activity_object.rb +29 -28
  9. data/app/models/actor.rb +27 -19
  10. data/app/models/channel.rb +48 -0
  11. data/app/views/contacts/_pendings.html.erb +1 -1
  12. data/app/views/devise/registrations/_edit_user.html.erb +0 -25
  13. data/app/views/devise/registrations/edit.html.erb +1 -0
  14. data/app/views/layouts/_footer.html.erb +1 -1
  15. data/app/views/layouts/_header_dropdown_menu_sessions.html.erb +5 -2
  16. data/app/views/settings/_language.html.erb +32 -0
  17. data/app/views/settings/_notifications.html.erb +1 -1
  18. data/config/locales/en.yml +5 -0
  19. data/config/locales/es.yml +7 -0
  20. data/db/migrate/20120103103125_add_channels.rb +88 -0
  21. data/db/migrate/20120109081509_update_notify_permissions.rb +15 -0
  22. data/lib/social_stream/base/engine.rb +10 -2
  23. data/lib/social_stream/base/version.rb +1 -1
  24. data/lib/social_stream/controllers/i18n_integration.rb +29 -0
  25. data/lib/social_stream/controllers/subjects.rb +19 -0
  26. data/lib/social_stream/models/object.rb +12 -26
  27. data/lib/social_stream/models/subject.rb +2 -24
  28. data/lib/social_stream/models/subtype.rb +80 -0
  29. data/lib/social_stream/models/supertype.rb +16 -3
  30. data/lib/social_stream/views/settings/base.rb +5 -0
  31. data/lib/social_stream-base.rb +7 -4
  32. data/lib/tasks/db/populate.rake +1 -0
  33. data/spec/controllers/settings_controller_spec.rb +1 -1
  34. data/spec/spec_helper.rb +3 -0
  35. metadata +67 -61
  36. data/spec/dummy/app/helpers/application_helper.rb +0 -2
@@ -0,0 +1,29 @@
1
+ module SocialStream
2
+ module Controllers
3
+ # Common methods added to ApplicationController
4
+ module I18nIntegration
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ before_filter :set_locale
9
+ end
10
+
11
+ module InstanceMethods
12
+ # Set locale as per params, user preference or default
13
+ def set_locale
14
+ I18n.locale = params[:locale] || user_preferred_locale || extract_locale_from_accept_language_header || I18n.default_locale
15
+ end
16
+
17
+ private
18
+ def extract_locale_from_accept_language_header
19
+ return nil if request.env['HTTP_ACCEPT_LANGUAGE'].nil?
20
+ (request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).map{|l| l.to_sym} & I18n.available_locales).first
21
+ end
22
+
23
+ def user_preferred_locale
24
+ current_user.language if user_signed_in?
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ module SocialStream
2
+ module Controllers
3
+ module Subjects
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ inherit_resources
8
+ end
9
+
10
+ module InstanceMethods
11
+ # Overwrite {SocialStream::Controllers::Helpers::InstanceMethods#profile_subject}
12
+ def profile_subject
13
+ !resource.new? && resource || current_subject
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
@@ -10,12 +10,11 @@ module SocialStream
10
10
  attr_writer :_relation_ids
11
11
  attr_accessor :_activity_parent_id
12
12
 
13
- belongs_to :activity_object,
14
- :validate => true,
15
- :autosave => true,
16
- :dependent => :destroy
13
+ subtype_of :activity_object,
14
+ :build => { :object_type => to_s }
17
15
 
18
- has_many :activity_object_activities, :through => :activity_object
16
+ has_one :channel, :through => :activity_object
17
+ has_many :activity_object_activities, :through => :activity_object
19
18
 
20
19
  # before_create :create_activity_object_with_type
21
20
 
@@ -23,31 +22,18 @@ module SocialStream
23
22
  validates_presence_of :author_id, :owner_id, :user_author_id
24
23
 
25
24
  after_create :create_post_activity
26
- after_update :create_update_activity
25
+ # Disable update activity for now
26
+ # It usually appears repeated in the wall and provides no useful information
27
+ #after_update :create_update_activity
27
28
  end
29
+
30
+ scope :authored_by, lambda { |subject|
31
+ joins(:activity_object).
32
+ merge(ActivityObject.authored_by(subject))
33
+ }
28
34
  end
29
35
 
30
36
  module InstanceMethods
31
- def activity_object!
32
- activity_object || build_activity_object(:object_type => self.class.to_s)
33
- end
34
-
35
- # Delegate missing methods to {ActivityObject}, if they exist there
36
- def method_missing(method, *args, &block)
37
- super
38
- rescue NameError => object_error
39
- # These methods must be raised to avoid loops (the :activity_object association calls here again)
40
- exceptions = [ :_activity_object_id ]
41
- raise object_error if exceptions.include?(method)
42
-
43
- activity_object!.__send__ method, *args, &block
44
- end
45
-
46
- # {ActivityObject} handles some methods
47
- def respond_to? *args
48
- super || activity_object!.respond_to?(*args)
49
- end
50
-
51
37
  # Was the author represented with this {SocialStream::Models::Object object} was created?
52
38
  def represented_author?
53
39
  author_id == user_author_id
@@ -21,10 +21,8 @@ module SocialStream
21
21
  extend ActiveSupport::Concern
22
22
 
23
23
  included do
24
- belongs_to :actor,
25
- :validate => true,
26
- :autosave => true,
27
- :dependent => :destroy
24
+ subtype_of :actor,
25
+ :build => { :subject_type => to_s }
28
26
 
29
27
  has_one :profile, :through => :actor
30
28
 
@@ -78,29 +76,9 @@ module SocialStream
78
76
  end
79
77
 
80
78
  module InstanceMethods
81
- def actor!
82
- actor || build_actor(:subject_type => self.class.to_s)
83
- end
84
-
85
79
  def to_param
86
80
  slug
87
81
  end
88
-
89
- # Delegate missing methods to {Actor}, if they exist there
90
- def method_missing(method, *args, &block)
91
- super
92
- rescue NameError => subject_error
93
- # These methods must be raised to avoid loops (the :actor association calls here again)
94
- exceptions = [ :_actor_id ]
95
- raise subject_error if exceptions.include?(method)
96
-
97
- actor!.__send__ method, *args, &block
98
- end
99
-
100
- # {Actor} handles some methods
101
- def respond_to? *args
102
- super || actor!.respond_to?(*args)
103
- end
104
82
  end
105
83
 
106
84
  module ClassMethods
@@ -0,0 +1,80 @@
1
+ require 'active_support/concern'
2
+
3
+ module SocialStream #:nodoc:
4
+ module Models
5
+ # Common methods for models that have a {SocialStream::Models::Supertype}
6
+ module Subtype
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ class << self
11
+ attr_reader :supertype_name, :supertype_options
12
+ end
13
+
14
+ belongs_to supertype_name, {
15
+ :validate => true,
16
+ :autosave => true,
17
+ :dependent => :destroy
18
+ }.merge(supertype_options[:belongs] || {})
19
+
20
+ class_eval <<-EOS
21
+ def #{ supertype_name }! # def actor!
22
+ #{ supertype_name } || # actor ||
23
+ # FIXME: ruby1.9 remove .inspect
24
+ build_#{ supertype_name }(#{ supertype_options[:build].inspect }) # build_actor(:subject_type => "User")
25
+ end # end
26
+
27
+ EOS
28
+
29
+ alias_method :supertype!, "#{ supertype_name }!"
30
+
31
+ before_validation :supertype!
32
+ end
33
+
34
+ module ClassMethods
35
+ def supertype_foreign_key
36
+ "#{ supertype_name }_id"
37
+ end
38
+ end
39
+
40
+ module InstanceMethods
41
+ # Delegate missing methods to supertype, if they exist there
42
+ def method_missing(method, *args, &block)
43
+ super
44
+ rescue NameError => subtype_error
45
+ # These methods must be raised to avoid loops
46
+ # (the @supertype_name association (i.e. :actor) calls here again)
47
+ exceptions = [ "_#{ self.class.supertype_foreign_key }".to_sym ] # [ :_actor_id ]
48
+ raise subtype_error if exceptions.include?(method)
49
+
50
+ begin
51
+ supertype!.__send__ method, *args, &block
52
+ # We rescue supertype's NameErrors so methods not defined are raised from
53
+ # the subtype. Example: user.foo should raise "foo is not defined in user"
54
+ # and not "in actor"
55
+ rescue NameError => supertype_error
56
+ raise subtype_error
57
+ end
58
+ end
59
+
60
+ # {SocialStream::Models::Supertype} handles some methods
61
+ def respond_to? *args
62
+ super || supertype!.respond_to?(*args)
63
+ end
64
+ end
65
+
66
+ module ActiveRecord
67
+ extend ActiveSupport::Concern
68
+
69
+ module ClassMethods
70
+ # This class is a subtype. Its supertype class is name
71
+ def subtype_of name, options = {}
72
+ @supertype_name = name
73
+ @supertype_options = options
74
+ include SocialStream::Models::Subtype
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -2,9 +2,10 @@ require 'active_support/concern'
2
2
 
3
3
  module SocialStream #:nodoc:
4
4
  module Models
5
- # Common methods for models that have subtypes. Currently, there are two supertypes:
6
- # * Actor: participates in the social network and has ties with other actors. Its subtypes are subjects, like user or group
7
- # * ActivityObject: created and managed by actors in activities. Its subtypes are objects, like post or comment
5
+ # Common methods for models having many {SocialStream::Models::Subtype subtypes}.
6
+ # Currently, there are two {SocialStream::Models::Supertype supertypes}:
7
+ # * {Actor}: participates in the social network and has {Tie Ties} with other actors. Its subtypes are {SocialStream::Models::Subject subjects}, such as {User} or {Group}
8
+ # * {ActivityObject}: created and managed by {Actor Actors} in {Activity Activities}. Its subtypes are {SocialStream::Models::Object objects}, like {Post} or {Comment}
8
9
  module Supertype
9
10
  extend ActiveSupport::Concern
10
11
 
@@ -32,6 +33,18 @@ module SocialStream #:nodoc:
32
33
  end # end
33
34
  end
34
35
  end
36
+
37
+ module ActiveRecord
38
+ extend ActiveSupport::Concern
39
+
40
+ module ClassMethods
41
+ # This class is a supertype. Subtype classes are known as name
42
+ def supertype_of name
43
+ @subtypes_name = name
44
+ include SocialStream::Models::Supertype
45
+ end
46
+ end
47
+ end
35
48
  end
36
49
  end
37
50
  end
@@ -15,6 +15,11 @@ module SocialStream
15
15
  }
16
16
  end
17
17
 
18
+ items << {
19
+ :key => 'language',
20
+ :html => render(:partial => "language")
21
+ }
22
+
18
23
  items << {
19
24
  :key => 'notifications',
20
25
  :html => render(:partial => "notifications")
@@ -10,15 +10,18 @@ module SocialStream
10
10
  autoload :TestHelpers, 'social_stream/test_helpers'
11
11
 
12
12
  module Controllers
13
+ autoload :I18nIntegration, 'social_stream/controllers/i18n_integration'
13
14
  autoload :CancanDeviseIntegration, 'social_stream/controllers/cancan_devise_integration'
14
- autoload :Helpers, 'social_stream/controllers/helpers'
15
- autoload :Objects, 'social_stream/controllers/objects'
15
+ autoload :Helpers, 'social_stream/controllers/helpers'
16
+ autoload :Objects, 'social_stream/controllers/objects'
17
+ autoload :Subjects, 'social_stream/controllers/subjects'
16
18
  end
17
19
 
18
20
  module Models
19
- autoload :Supertype, 'social_stream/models/supertype'
20
- autoload :Subject, 'social_stream/models/subject'
21
21
  autoload :Object, 'social_stream/models/object'
22
+ autoload :Subject, 'social_stream/models/subject'
23
+ autoload :Subtype, 'social_stream/models/subtype'
24
+ autoload :Supertype, 'social_stream/models/supertype'
22
25
  end
23
26
 
24
27
  module Views
@@ -9,6 +9,7 @@ namespace :db do
9
9
 
10
10
  desc "Create populate data"
11
11
  task :create => :environment do
12
+ require 'forgery'
12
13
 
13
14
  LOGOS_PATH = File.join(Rails.root, 'lib', 'logos')
14
15
  USERS = (ENV["USERS"] || 9).to_i
@@ -17,7 +17,7 @@ describe SettingsController do
17
17
 
18
18
  it "should render index after update_all" do
19
19
  put :update_all
20
- assert_response :success
20
+ response.should redirect_to(:settings)
21
21
  end
22
22
 
23
23
  describe "Notification settings" do
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # Configure Rails Envinronment
2
2
  ENV["RAILS_ENV"] ||= "test"
3
3
 
4
+ # Do not check ImageMagick<=>Rmagick versions
5
+ RMAGICK_BYPASS_VERSION_TEST = true
6
+
4
7
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
8
  require "rspec/rails"
6
9