Skip to content

Commit

Permalink
Some Rails4 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
stephankaag committed Jul 22, 2013
1 parent 112b9f9 commit b19f631
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ else
gem 'sprockets', git: 'https://github.com/SamSaffron/sprockets.git', branch: 'rails-compat'
gem 'redis-rails'
gem 'seed-fu'
gem 'activerecord-postgres-hstore'
gem 'active_attr'
end

gem 'redis'
Expand All @@ -71,8 +73,6 @@ gem 'rails_multisite', path: 'vendor/gems/rails_multisite'
gem 'simple_handlebars_rails', path: 'vendor/gems/simple_handlebars_rails'

gem 'redcarpet', require: false
gem 'activerecord-postgres-hstore'
gem 'active_attr' # until we get ActiveModel::Model with Rails 4
gem 'airbrake', '3.1.2', require: false # errbit is broken with 3.1.3 for now
gem 'clockwork', require: false
gem 'eventmachine'
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ GEM
minitest (4.7.3)
mocha (0.13.3)
metaclass (~> 0.0.1)
multi_json (1.7.6)
multi_json (1.7.7)
multipart-post (1.2.0)
mustache (0.99.4)
net-scp (1.1.0)
Expand Down
10 changes: 0 additions & 10 deletions Gemfile_rails4.lock
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ GEM
rack-test (~> 0.6.2)
actionpack-action_caching (1.0.0)
actionpack (>= 4.0.0.beta, < 5.0)
active_attr (0.8.2)
activemodel (>= 3.0.2, < 4.1)
activesupport (>= 3.0.2, < 4.1)
activemodel (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
Expand All @@ -137,10 +134,6 @@ GEM
activesupport (= 4.0.0)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activerecord-postgres-hstore (0.7.6)
activerecord (>= 3.1)
pg-hstore (>= 1.1.5)
rake
activesupport (4.0.0)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
Expand Down Expand Up @@ -316,7 +309,6 @@ GEM
redis
ruby-openid
pg (0.15.1)
pg-hstore (1.1.7)
polyglot (0.3.3)
progress (2.4.0)
protected_attributes (1.0.3)
Expand Down Expand Up @@ -478,9 +470,7 @@ PLATFORMS

DEPENDENCIES
actionpack-action_caching
active_attr
active_model_serializers!
activerecord-postgres-hstore
airbrake (= 3.1.2)
annotate!
barber
Expand Down
12 changes: 7 additions & 5 deletions app/models/discourse_version_check.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class DiscourseVersionCheck

# include ActiveModel::Model <-- If we were using Rails 4, we could use this instead of active_attr
include ActiveAttr::Attributes
include ActiveAttr::MassAssignment
include ActiveModel::Serialization
if rails4?
include ActiveModel::Model
else
include ActiveAttr::Attributes
include ActiveAttr::MassAssignment
include ActiveModel::Serialization
end

attr_accessor :latest_version, :critical_updates, :installed_version, :installed_sha, :missing_versions_count, :updated_at

Expand Down
4 changes: 1 addition & 3 deletions app/models/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ def recover!
self.title = TextCleaner.clean_title(TextSentinel.title_sentinel(title).text) if errors[:title].empty?
end

if rails4?
store_accessor :meta_data
else
unless rails4?
serialize :meta_data, ActiveRecord::Coders::Hstore
end

Expand Down
20 changes: 15 additions & 5 deletions app/models/user_email_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@ class UserEmailObserver < ActiveRecord::Observer
observe :notification

def after_commit(notification)
if notification.send(:transaction_include_action?, :create)
notification_type = Notification.types[notification.notification_type]
if rails4?
if notification.send(:transaction_include_any_action?, [:create])
notification_type = Notification.types[notification.notification_type]

# Delegate to email_user_{{NOTIFICATION_TYPE}} if exists
email_method = :"email_user_#{notification_type.to_s}"
send(email_method, notification) if respond_to?(email_method)
# Delegate to email_user_{{NOTIFICATION_TYPE}} if exists
email_method = :"email_user_#{notification_type.to_s}"
send(email_method, notification) if respond_to?(email_method)
end
else
if notification.send(:transaction_include_action?, :create)
notification_type = Notification.types[notification.notification_type]

# Delegate to email_user_{{NOTIFICATION_TYPE}} if exists
email_method = :"email_user_#{notification_type.to_s}"
send(email_method, notification) if respond_to?(email_method)
end
end
end

Expand Down
22 changes: 16 additions & 6 deletions lib/discourse_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@ class DiscourseObserver < ActiveRecord::Observer
# Outside of test mode, use after_commit
class DiscourseObserver < ActiveRecord::Observer
def after_commit(model)
if model.send(:transaction_include_action?, :create)
after_create_delegator(model)
end

if model.send(:transaction_include_action?, :destroy)
after_destroy_delegator(model)
if rails4?
if model.send(:transaction_include_any_action?, [:create])
after_create_delegator(model)
end

if model.send(:transaction_include_any_action?, [:destroy])
after_destroy_delegator(model)
end
else
if model.send(:transaction_include_action?, :create)
after_create_delegator(model)
end

if model.send(:transaction_include_action?, :destroy)
after_destroy_delegator(model)
end
end

end
Expand Down

0 comments on commit b19f631

Please sign in to comment.