* fix viewable_notifications if no join table, and try to fix build again

This commit is contained in:
Seth Call 2015-06-09 09:32:12 -05:00
parent b179869606
commit fe011b48c6
7 changed files with 26 additions and 10 deletions

View File

@ -16,7 +16,7 @@ ActiveAdmin.register JamRuby::BroadcastNotification, :as => 'BroadcastNotificati
row :title
row :message
row :button_label
row :button_text
row :button_url
row :frequency
row :frequency_distribution
end

View File

@ -1,19 +1,22 @@
module JamRuby
class BroadcastNotification < ActiveRecord::Base
attr_accessible :title, :message, :button_label, :frequency
attr_accessible :title, :message, :button_label, :frequency, :button_url, as: :admin
has_many :user_views, class_name: 'JamRuby::BroadcastNotificationView', dependent: :destroy
validates :button_label, presence: true, length: {maximum: 14}
validates :message, presence: true, length: {maximum: 200}
validates :title, presence: true, length: {maximum: 50}
def self.next_broadcast(user)
self.viewable_notifications(user).limit(1).first
end
def self.viewable_notifications(user)
self.select('broadcast_notifications.*, bnv.updated_at AS bnv_updated_at')
.joins('INNER JOIN broadcast_notification_views AS bnv ON bnv.broadcast_notification_id = broadcast_notifications.id')
.where(['bnv.user_id = ?',user.id])
.joins("LEFT OUTER JOIN broadcast_notification_views AS bnv ON bnv.broadcast_notification_id = broadcast_notifications.id AND (bnv.user_id IS NULL OR (bnv.user_id = '#{user.id}'))")
.where(['broadcast_notifications.frequency > 0'])
.where(['broadcast_notifications.frequency > bnv.view_count'])
.where(['bnv.user_id IS NULL OR broadcast_notifications.frequency > bnv.view_count'])
.order('bnv_updated_at')
end

View File

@ -799,9 +799,9 @@ FactoryGirl.define do
end
factory :broadcast_notification, :class => JamRuby::BroadcastNotification do
title Faker::Lorem.sentence[0...64]
message Faker::Lorem.paragraph[0...256]
button_label Faker::Lorem.words(2).join(' ')[0...32]
title Faker::Lorem.sentence[0...50]
message Faker::Lorem.paragraph[0...200]
button_label Faker::Lorem.words(2).join(' ')[0...14]
frequency 3
end

View File

@ -27,13 +27,21 @@ describe BroadcastNotification do
end
it 'loads viewable broadcasts for a user' do
broadcast1.touch
broadcast2.touch
broadcast3.touch
broadcast4.touch
bns = BroadcastNotification.viewable_notifications(user1)
bns.count.should eq(4)
broadcast2.frequency.times { |nn| broadcast2.did_view(user1) }
broadcast3.did_view(user1)
broadcast1.did_view(user1)
broadcast4.did_view(user2)
bns = BroadcastNotification.viewable_notifications(user1)
expect(bns.count).to be(2)
expect(bns.count).to be(3)
expect(bns[0].id).to eq(broadcast3.id)
expect(bns.detect {|bb| bb.id==broadcast2.id }).to be_nil
expect(BroadcastNotification.next_broadcast(user1).id).to eq(broadcast3.id)

View File

@ -19,7 +19,7 @@ context.JK.ClientInit = class ClientInit
setTimeout(this.checkBroadcastNotification, 3000)
checkBroadcastNotification: () =>
if context.JK.userId
if context.JK.currentUserId
broadcastActions.load.triggerPromise()

View File

@ -137,6 +137,7 @@ EOF
# cache all gems local, and tell bundle to use local gems only
#bundle install --path vendor/bundle --local
# prepare production acssets
RAILS_ENV=production bundle install --path vendor/bundle
rm -rf $DIR/public/assets
bundle exec rake assets:precompile RAILS_ENV=production

File diff suppressed because one or more lines are too long