add tests

make tests work
make posts from python work
This commit is contained in:
Tyrel Souza 2014-04-09 14:12:14 -04:00
parent c6d2a47b2a
commit 7833c04d3d
12 changed files with 54 additions and 60 deletions

View File

@ -22,6 +22,7 @@ gem 'foundation-rails'
gem 'devise'
gem 'jbuilder'
group :development do
gem 'foreman'
gem 'spring'

View File

@ -1,26 +1,25 @@
class CampaignsController < ApplicationController
before_action :set_campaign, only: [:show, :edit, :update, :destroy]
# GET /campaigns
def index
@campaigns = Campaign.all
end
# GET /campaigns/1
def show
respond_to do |format|
format.json { render json: @campaign }
format.html { render html: @campaign }
end
end
# GET /campaigns/new
def new
@campaign = Campaign.new
@campaign.videolistings.build
end
# GET /campaigns/1/edit
def edit
end
# POST /campaigns
def create
@campaign = Campaign.new campaign_params
@ -34,7 +33,6 @@ class CampaignsController < ApplicationController
end
end
# PATCH/PUT /campaigns/1
def update
if @campaign.update(campaign_params)
redirect_to @campaign, notice: 'Campaign was successfully updated.'
@ -43,30 +41,28 @@ class CampaignsController < ApplicationController
end
end
# DELETE /campaigns/1
def destroy
@campaign.destroy
redirect_to campaigns_url, notice: 'Campaign was successfully destroyed.'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_campaign
@campaign = Campaign.find_by_clientid(params[:clientid]) || not_found
end
# Only allow a trusted parameter "white list" through.
def campaign_params
params.require(:campaign).permit(:id, :clientid, :listingcode, :billingcode, :advertisername, :address1,
:address2, :city, :state, :zip, :emailaddress, :customerfirstname,
:customerlastname, :salesrep, :salesrepemail, :businessphone,
:contactphone, :websiteurl,
videolistings_attributes: [:id, :videocode, :producttypeid, :remoteassetsarchive, :voiceoverselection,
:musicselection, :clientprovidedscript, :keywords, :focus, :notes, :asseturls,])
videolistings_attributes: [:id, :videocode, :producttypeid, :remoteassetsarchive,
:voiceoverselection, :musicselection, :clientprovidedscript,
:keywords, :focus, :notes, :asseturls,])
end
def not_found
raise ActionController::RoutingError.new("Not Found by clientid")
end
end

View File

@ -1,5 +1,5 @@
class Campaign < ActiveRecord::Base
has_many :videolistings
has_many :videolistings, :dependent => :delete_all
accepts_nested_attributes_for :videolistings
validates :clientid, presence: true, uniqueness: true
validates :billingcode, uniqueness: true

View File

@ -23,9 +23,9 @@
<td><%= campaign.city %></td>
<td><%= campaign.state %></td>
<td><%= campaign.zip %></td>
<td><%= link_to 'Show', campaign %></td>
<td><%= link_to 'Edit', edit_campaign_path(campaign) %></td>
<td><%= link_to 'Destroy', campaign, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Show', campaign_path(campaign.clientid) %></td>
<td><%= link_to 'Edit', edit_campaign_path(campaign.clientid) %></td>
<td><%= link_to 'Destroy', campaign_path(campaign.clientid), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140408181813) do
ActiveRecord::Schema.define(version: 20140409152531) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20140408181813) do
t.string "websiteurl"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "processed"
end
create_table "delayed_jobs", force: true do |t|

View File

@ -0,0 +1,19 @@
require 'spec_helper'
describe CampaignsController do
let(:campaign){ attributes_for :campaign }
let(:videolisting){ attributes_for :videolisting }
it 'creates a campaign from json post' do
post :create, campaign: campaign
expect(response.status).to be 302
expect(Campaign.last.clientid).to eq "clientid1"
end
it 'creates a campaign with a nested videolisting' do
campaign[:videolistings_attributes] = [videolisting,]
post :create, campaign: campaign
expect(Campaign.last.videolistings.last.videocode).to eq "video1"
expect(Campaign.last.videolistings.count).to eq 1
end
end

View File

@ -1,6 +0,0 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :admin do
end
end

View File

@ -1,23 +1,22 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :campaign do
clientid "MyString"
listingcode "MyString"
billingcode "MyString"
advertisername "MyString"
address1 "MyString"
address2 "MyString"
city "MyString"
state "MyString"
zip "MyString"
emailaddress "MyString"
customerfirstname "MyString"
customerlastname "MyString"
salesrep "MyString"
salesrepemail "MyString"
businessphone "MyString"
contactphone "MyString"
websiteurl "MyString"
sequence(:clientid) { |x| "clientid#{x}" }
sequence(:billingcode) { |x| "billingcode#{x}" }
sequence(:listingcode) { |x| "listingcode#{x}" }
advertisername "MyName1"
address1 "addr1_1"
address2 "addr2_1"
city "Mycity"
state "MyState"
zip "88888"
emailaddress "google@google.com"
customerfirstname "Name"
customerlastname "Last"
salesrep "SalesGuy"
salesrepemail "email@sales.com"
businessphone "8005882300"
contactphone "8005882301"
websiteurl "http://www.google.com/"
processed false
end
end

View File

@ -1,6 +0,0 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :user do
end
end

View File

@ -2,8 +2,8 @@
FactoryGirl.define do
factory :videolisting do
videocode "MyString"
producttypeid "MyString"
sequence(:videocode) {|x| "video#{x}" }
producttypeid "IMPORTANT"
remoteassetsarchive "MyString"
voiceoverselection "MyString"
musicselection "MyString"

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe Admin do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -1,5 +0,0 @@
require 'spec_helper'
describe User do
pending "add some examples to (or delete) #{__FILE__}"
end