Added tests, cleaning up, TDDing, javascript

This commit is contained in:
Tyrel Souza 2014-04-28 14:16:43 -04:00
parent 3b784fb493
commit 7ff11b8827
12 changed files with 107 additions and 6 deletions

View File

@ -23,6 +23,7 @@ gem 'devise'
gem 'jbuilder'
gem 'bootstrap-tagsinput-rails'
gem 'cocoon', :git => 'git://github.com/nathanvda/cocoon'
gem 'zeroclipboard-rails'
group :development do

View File

@ -227,6 +227,8 @@ GEM
crack (>= 0.3.2)
xpath (2.0.0)
nokogiri (~> 1.3)
zeroclipboard-rails (0.0.12)
railties (>= 3.1)
PLATFORMS
ruby
@ -270,3 +272,4 @@ DEPENDENCIES
uglifier
unicorn
webmock
zeroclipboard-rails

View File

@ -14,4 +14,5 @@
//= require jquery_ujs
//= require bootstrap-tagsinput
//= require cocoon
//= require zeroclipboard
//= require_tree .

View File

@ -0,0 +1,6 @@
/**
* Created by tsouza on 4/28/14.
*/

View File

@ -1,5 +1,5 @@
class VideolistingsController < ApplicationController
before_action :set_videolisting, only: [:publish]
before_action :set_videolisting, only: [:publish, :show]
def publish
if @videolisting.published?
@ -14,6 +14,11 @@ class VideolistingsController < ApplicationController
end
end
def show
@videolisting
end
private
# Use callbacks to share common setup or constraints between actions.
def set_videolisting

View File

@ -16,7 +16,12 @@ class Campaign < ActiveRecord::Base
errors.add(:base, 'Must add at least one Videolisting') if self.videolistings.blank?
end
def video_completion_percent
published = videolistings.where({published: true}).length
((published.to_f / videolistings.count.to_f) * 100).to_i
rescue
0
end
def send_to_better_video
if self.processed_changed? && self.processed == true

View File

@ -1,4 +1,10 @@
<ul>
<% if videolisting.published %>
<li>
<p><strong>Published Video</strong><br>
<%= link_to "View Preview and Get Code", campaign_videolisting_path(@campaign.listingcode, videolisting.videocode) %>
</li>
<% end %>
<li>
<p><strong>Video Code</strong><br>
<%= videolisting.videocode %></p>

View File

@ -6,8 +6,9 @@
<thead>
<tr>
<th>Listing Code (Form Hash)</th>
<th>Advertiser</th>
<th>Processed?</th>
<th>Billing Code</th>
<th>Percent of Videos Completed</th>
<th>Address</th>
<th>City</th>
<th>State</th>
@ -20,8 +21,9 @@
<% @campaigns.each do |campaign| %>
<tr>
<td><%= link_to campaign.listingcode, campaign_path(campaign.listingcode) %></td>
<td><%= campaign.advertisername %></td>
<td><i class="glyphicon glyphicon-<% if campaign.processed? %>ok<% else %>remove<% end %>"></i> </td>
<td><%= campaign.billingcode %></td>
<td><%= number_to_percentage(campaign.video_completion_percent, precision: 0) %></td>
<td><%= campaign.address %></td>
<td><%= campaign.city %></td>
<td><%= campaign.state %></td>

View File

@ -5,7 +5,7 @@
<meta name="ROBOTS" content="NOODP" />
<title><%= title %></title>
<%= stylesheet_link_tag :application, :media => 'all' %>
<%= yield :js_head %>
<%= csrf_meta_tags %>
</head>
<body class="<%= body_class %>">

View File

@ -0,0 +1,46 @@
<div class="container">
<section>
<div class="pull-right">
<%= link_to 'Back to Campaign', campaign_path(@videolisting.campaign.listingcode) %> |
<%= link_to 'Back to Campaigns List', campaigns_path %>
</div>
<h1><%= @videolisting.campaign.advertisername %> </h1>
<hr>
<p id="notice"><%= notice %></p>
<div class="row">
<div class="col-md-8">
<ul>
<li><h2>Video Code</h2>
Here is the video code:
<input type="text" id="videocode" value="<%= @videolisting.videocode %>"> <button class='clip_button' data-clipboard-target='videocode' data-clipboard-text='<%= @videolisting.videocode %>' id='clip_button' title='Click me to copy to clipboard.'>
<b>Copy To Clipboard...</b>
</button>
<hr>
<h3>Preview Image</h3>
<%= image_tag(@videolisting.get_preview_url) %>
</li>
</ul>
</div>
</div>
</section>
</div>
<% content_for :js_head do %>
<script>
$(document).on('ready page:load', function () {
var clip = new ZeroClipboard($("#clip_button"));
clip.on( "ready", function(readyEvent){
clip.on("aftercopy", function(event) {
alert("Copied text to clipboard: " + event.data["text/plain"]);
});
});
});
</script>
<% end %>

View File

@ -9,7 +9,7 @@ FactoryGirl.define do
producttypeid 721
toneofvideo "Upbeat, targeting families but also show business functions."
voiceoverselection 3
published {|x| true }
published {|x| false }
sequence(:videocode) {|x| "video#{x}" }
end
end

View File

@ -14,4 +14,30 @@ describe Campaign, 'associations' do
expect(two.valid?).to be false
end
it 'shows how complete the videos are by percentage' do
camp = Campaign.new(campaign)
video_1 = FactoryGirl.create(:videolisting)
video_2 = FactoryGirl.create(:videolisting)
expect(camp.video_completion_percent).to eq(0) # no associations
camp.videolistings << video_1
camp.videolistings << video_2
camp.save
expect(camp.video_completion_percent).to eq(0)
camp.videolistings.first.published = true
camp.videolistings.first.save
expect(camp.video_completion_percent).to eq(50)
camp.videolistings.last.published = true
camp.videolistings.last.save
expect(camp.video_completion_percent).to eq(100)
end
end