VRFS-2855 first commit of broadcast data model
This commit is contained in:
parent
821ca9d76a
commit
d0d6da169f
|
|
@ -109,6 +109,7 @@ group :development, :test do
|
|||
gem 'database_cleaner', '0.7.0'
|
||||
gem 'launchy'
|
||||
gem 'faker', '1.3.0'
|
||||
gem 'puma'
|
||||
end
|
||||
|
||||
group :test do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
ActiveAdmin.register JamRuby::BroadcastNotification, :as => 'BroadcastNotification' do
|
||||
|
||||
menu :label => 'Notifications'
|
||||
|
||||
config.sort_order = 'created_at_desc'
|
||||
config.batch_actions = false
|
||||
config.clear_action_items!
|
||||
config.filters = false
|
||||
|
||||
action_item :only => :index do
|
||||
link_to "New Broadcast" , "broadcast_notifications/new"
|
||||
end
|
||||
|
||||
controller do
|
||||
|
||||
def create
|
||||
resource_class.create(params[:broadcast_notification])
|
||||
redirect_to(admin_broadcast_notifications_path)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -273,4 +273,5 @@ drop_position_unique_jam_track.sql
|
|||
recording_client_metadata.sql
|
||||
preview_support_mp3.sql
|
||||
jam_track_duration.sql
|
||||
sales.sql
|
||||
sales.sql
|
||||
broadcast_notifications.sql
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
CREATE TABLE broadcast_notifications (
|
||||
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
title VARCHAR(64),
|
||||
message VARCHAR(256),
|
||||
button_label VARCHAR(32),
|
||||
frequency INTEGER DEFAULT 0,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE broadcast_notification_views (
|
||||
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
user_id varchar(64) NOT NULL REFERENCES users(id),
|
||||
broadcast_notification_id varchar(64) NOT NULL REFERENCES broadcast_notifications(id) ON DELETE CASCADE,
|
||||
view_count INTEGER DEFAULT 0,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX user_broadcast_idx ON broadcast_notification_views(user_id, broadcast_notification_id);
|
||||
|
|
@ -62,6 +62,7 @@ group :test do
|
|||
gem 'resque_spec' #, :path => "/home/jam/src/resque_spec/"
|
||||
gem 'timecop'
|
||||
gem 'rspec-prof'
|
||||
gem 'byebug'
|
||||
end
|
||||
|
||||
# Specify your gem's dependencies in jam_ruby.gemspec
|
||||
|
|
|
|||
|
|
@ -209,6 +209,8 @@ require "jam_ruby/models/text_message"
|
|||
require "jam_ruby/models/sale"
|
||||
require "jam_ruby/models/sale_line_item"
|
||||
require "jam_ruby/models/recurly_transaction_web_hook"
|
||||
require "jam_ruby/models/broadcast_notification"
|
||||
require "jam_ruby/models/broadcast_notification_view"
|
||||
require "jam_ruby/jam_tracks_manager"
|
||||
require "jam_ruby/jam_track_importer"
|
||||
require "jam_ruby/jmep_manager"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
module JamRuby
|
||||
class BroadcastNotification < ActiveRecord::Base
|
||||
|
||||
attr_accessible :title, :message, :button_label, :frequency
|
||||
has_many :user_views, class_name: 'JamRuby::BroadcastNotificationView', dependent: :destroy
|
||||
|
||||
def frequency_distribution
|
||||
BroadcastNotificationView
|
||||
.where(broadcast_notification_id: self.id)
|
||||
.group(:view_count)
|
||||
.count
|
||||
end
|
||||
|
||||
def did_view(user)
|
||||
bnv = BroadcastNotificationView
|
||||
.where(broadcast_notification_id: self.id, user_id: user.id)
|
||||
.limit(1)
|
||||
.first
|
||||
bnv = user_views.new(user: user) unless bnv
|
||||
bnv.view_count += 1
|
||||
bnv.save
|
||||
bnv
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
module JamRuby
|
||||
class BroadcastNotificationView < ActiveRecord::Base
|
||||
|
||||
belongs_to :broadcast_notification, :class_name => 'JamRuby::BroadcastNotification'
|
||||
belongs_to :user, :class_name => 'JamRuby::User'
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -633,9 +633,9 @@ FactoryGirl.define do
|
|||
data Faker::Lorem.sentence
|
||||
end
|
||||
|
||||
factory :rsvp_slot, class: JamRuby::RsvpSlot do
|
||||
factory :rsvp_slot, :class => JamRuby::RsvpSlot do
|
||||
|
||||
proficiency_level 'beginner'
|
||||
proficiency_level "beginner"
|
||||
instrument { Instrument.find('electric guitar') }
|
||||
|
||||
factory :chosen_rsvp_slot do
|
||||
|
|
@ -643,10 +643,10 @@ FactoryGirl.define do
|
|||
user nil
|
||||
end
|
||||
|
||||
after(:create) { |rsvp_slot, evaluator|
|
||||
after(:create) do |rsvp_slot, evaluator|
|
||||
rsvp_request = FactoryGirl.create(:rsvp_request, user: evaluator.user)
|
||||
rsvp_request_rsvp_slot = FactoryGirl.create(:rsvp_request_rsvp_slot, chosen:true, rsvp_request: rsvp_request, rsvp_slot:rsvp_slot)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -686,7 +686,7 @@ FactoryGirl.define do
|
|||
end
|
||||
end
|
||||
|
||||
factory :rsvp_request_rsvp_slot, class: JamRuby::RsvpRequestRsvpSlot do
|
||||
factory :rsvp_request_rsvp_slot, :class => JamRuby::RsvpRequestRsvpSlot do
|
||||
chosen false
|
||||
end
|
||||
|
||||
|
|
@ -795,4 +795,12 @@ FactoryGirl.define do
|
|||
transaction_type JamRuby::RecurlyTransactionWebHook::FAILED_PAYMENT
|
||||
end
|
||||
end
|
||||
|
||||
factory :broadcast_notification, :class => JamRuby::BroadcastNotification do
|
||||
title Faker::Lorem.sentence
|
||||
message Faker::Lorem.paragraph
|
||||
button_label Faker::Lorem.words(2).join(' ')
|
||||
frequency 5
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
require 'byebug'
|
||||
require 'spec_helper'
|
||||
|
||||
describe BroadcastNotification do
|
||||
|
||||
let(:broadcast) { FactoryGirl.create(:broadcast_notification) }
|
||||
let(:user1) { FactoryGirl.create(:user) }
|
||||
let(:user2) { FactoryGirl.create(:user) }
|
||||
let(:user3) { FactoryGirl.create(:user) }
|
||||
let(:user4) { FactoryGirl.create(:user) }
|
||||
|
||||
it 'created broadcast' do
|
||||
expect(broadcast.title).not_to be_empty
|
||||
expect(broadcast.frequency).to be > 0
|
||||
end
|
||||
|
||||
it 'gets viewed' do
|
||||
bnv = broadcast.did_view(user1)
|
||||
expect(bnv.view_count).to be == 1
|
||||
end
|
||||
|
||||
it 'gets view incremented' do
|
||||
bnv = broadcast.did_view(user1)
|
||||
bnv = broadcast.did_view(user1)
|
||||
expect(bnv.view_count).to be >= 2
|
||||
end
|
||||
|
||||
it 'generages frequency distribution' do
|
||||
4.times { |nn| broadcast.did_view(user1) }
|
||||
5.times { |nn| broadcast.did_view(user2) }
|
||||
5.times { |nn| broadcast.did_view(user3) }
|
||||
8.times { |nn| broadcast.did_view(user4) }
|
||||
|
||||
distrib = broadcast.frequency_distribution
|
||||
|
||||
expect(distrib.count).to be == 3
|
||||
expect(distrib[4]).to be == 1
|
||||
expect(distrib[5]).to be == 2
|
||||
expect(distrib[8]).to be == 1
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Reference in New Issue