add tests
make tests work make posts from python work
This commit is contained in:
parent
c6d2a47b2a
commit
7833c04d3d
1
Gemfile
1
Gemfile
@ -22,6 +22,7 @@ gem 'foundation-rails'
|
|||||||
gem 'devise'
|
gem 'devise'
|
||||||
gem 'jbuilder'
|
gem 'jbuilder'
|
||||||
|
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem 'foreman'
|
gem 'foreman'
|
||||||
gem 'spring'
|
gem 'spring'
|
||||||
|
@ -1,26 +1,25 @@
|
|||||||
class CampaignsController < ApplicationController
|
class CampaignsController < ApplicationController
|
||||||
before_action :set_campaign, only: [:show, :edit, :update, :destroy]
|
before_action :set_campaign, only: [:show, :edit, :update, :destroy]
|
||||||
|
|
||||||
# GET /campaigns
|
|
||||||
def index
|
def index
|
||||||
@campaigns = Campaign.all
|
@campaigns = Campaign.all
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /campaigns/1
|
|
||||||
def show
|
def show
|
||||||
|
respond_to do |format|
|
||||||
|
format.json { render json: @campaign }
|
||||||
|
format.html { render html: @campaign }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /campaigns/new
|
|
||||||
def new
|
def new
|
||||||
@campaign = Campaign.new
|
@campaign = Campaign.new
|
||||||
@campaign.videolistings.build
|
@campaign.videolistings.build
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /campaigns/1/edit
|
|
||||||
def edit
|
def edit
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /campaigns
|
|
||||||
def create
|
def create
|
||||||
@campaign = Campaign.new campaign_params
|
@campaign = Campaign.new campaign_params
|
||||||
|
|
||||||
@ -34,7 +33,6 @@ class CampaignsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# PATCH/PUT /campaigns/1
|
|
||||||
def update
|
def update
|
||||||
if @campaign.update(campaign_params)
|
if @campaign.update(campaign_params)
|
||||||
redirect_to @campaign, notice: 'Campaign was successfully updated.'
|
redirect_to @campaign, notice: 'Campaign was successfully updated.'
|
||||||
@ -43,30 +41,28 @@ class CampaignsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /campaigns/1
|
|
||||||
def destroy
|
def destroy
|
||||||
@campaign.destroy
|
@campaign.destroy
|
||||||
redirect_to campaigns_url, notice: 'Campaign was successfully destroyed.'
|
redirect_to campaigns_url, notice: 'Campaign was successfully destroyed.'
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
|
||||||
def set_campaign
|
def set_campaign
|
||||||
@campaign = Campaign.find_by_clientid(params[:clientid]) || not_found
|
@campaign = Campaign.find_by_clientid(params[:clientid]) || not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
# Only allow a trusted parameter "white list" through.
|
|
||||||
def campaign_params
|
def campaign_params
|
||||||
params.require(:campaign).permit(:id, :clientid, :listingcode, :billingcode, :advertisername, :address1,
|
params.require(:campaign).permit(:id, :clientid, :listingcode, :billingcode, :advertisername, :address1,
|
||||||
:address2, :city, :state, :zip, :emailaddress, :customerfirstname,
|
:address2, :city, :state, :zip, :emailaddress, :customerfirstname,
|
||||||
:customerlastname, :salesrep, :salesrepemail, :businessphone,
|
:customerlastname, :salesrep, :salesrepemail, :businessphone,
|
||||||
:contactphone, :websiteurl,
|
:contactphone, :websiteurl,
|
||||||
videolistings_attributes: [:id, :videocode, :producttypeid, :remoteassetsarchive, :voiceoverselection,
|
videolistings_attributes: [:id, :videocode, :producttypeid, :remoteassetsarchive,
|
||||||
:musicselection, :clientprovidedscript, :keywords, :focus, :notes, :asseturls,])
|
:voiceoverselection, :musicselection, :clientprovidedscript,
|
||||||
|
:keywords, :focus, :notes, :asseturls,])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def not_found
|
def not_found
|
||||||
raise ActionController::RoutingError.new("Not Found by clientid")
|
raise ActionController::RoutingError.new("Not Found by clientid")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
class Campaign < ActiveRecord::Base
|
class Campaign < ActiveRecord::Base
|
||||||
has_many :videolistings
|
has_many :videolistings, :dependent => :delete_all
|
||||||
accepts_nested_attributes_for :videolistings
|
accepts_nested_attributes_for :videolistings
|
||||||
validates :clientid, presence: true, uniqueness: true
|
validates :clientid, presence: true, uniqueness: true
|
||||||
validates :billingcode, uniqueness: true
|
validates :billingcode, uniqueness: true
|
||||||
|
@ -23,9 +23,9 @@
|
|||||||
<td><%= campaign.city %></td>
|
<td><%= campaign.city %></td>
|
||||||
<td><%= campaign.state %></td>
|
<td><%= campaign.state %></td>
|
||||||
<td><%= campaign.zip %></td>
|
<td><%= campaign.zip %></td>
|
||||||
<td><%= link_to 'Show', campaign %></td>
|
<td><%= link_to 'Show', campaign_path(campaign.clientid) %></td>
|
||||||
<td><%= link_to 'Edit', edit_campaign_path(campaign) %></td>
|
<td><%= link_to 'Edit', edit_campaign_path(campaign.clientid) %></td>
|
||||||
<td><%= link_to 'Destroy', campaign, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
<td><%= link_to 'Destroy', campaign_path(campaign.clientid), method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20140408181813) do
|
|||||||
t.string "websiteurl"
|
t.string "websiteurl"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.boolean "processed"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "delayed_jobs", force: true do |t|
|
create_table "delayed_jobs", force: true do |t|
|
||||||
|
19
spec/controllers/campaigns_controller_spec.rb
Normal file
19
spec/controllers/campaigns_controller_spec.rb
Normal 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
|
@ -1,6 +0,0 @@
|
|||||||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
|
||||||
|
|
||||||
FactoryGirl.define do
|
|
||||||
factory :admin do
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,23 +1,22 @@
|
|||||||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :campaign do
|
factory :campaign do
|
||||||
clientid "MyString"
|
sequence(:clientid) { |x| "clientid#{x}" }
|
||||||
listingcode "MyString"
|
sequence(:billingcode) { |x| "billingcode#{x}" }
|
||||||
billingcode "MyString"
|
sequence(:listingcode) { |x| "listingcode#{x}" }
|
||||||
advertisername "MyString"
|
advertisername "MyName1"
|
||||||
address1 "MyString"
|
address1 "addr1_1"
|
||||||
address2 "MyString"
|
address2 "addr2_1"
|
||||||
city "MyString"
|
city "Mycity"
|
||||||
state "MyString"
|
state "MyState"
|
||||||
zip "MyString"
|
zip "88888"
|
||||||
emailaddress "MyString"
|
emailaddress "google@google.com"
|
||||||
customerfirstname "MyString"
|
customerfirstname "Name"
|
||||||
customerlastname "MyString"
|
customerlastname "Last"
|
||||||
salesrep "MyString"
|
salesrep "SalesGuy"
|
||||||
salesrepemail "MyString"
|
salesrepemail "email@sales.com"
|
||||||
businessphone "MyString"
|
businessphone "8005882300"
|
||||||
contactphone "MyString"
|
contactphone "8005882301"
|
||||||
websiteurl "MyString"
|
websiteurl "http://www.google.com/"
|
||||||
|
processed false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
|
||||||
|
|
||||||
FactoryGirl.define do
|
|
||||||
factory :user do
|
|
||||||
end
|
|
||||||
end
|
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :videolisting do
|
factory :videolisting do
|
||||||
videocode "MyString"
|
sequence(:videocode) {|x| "video#{x}" }
|
||||||
producttypeid "MyString"
|
producttypeid "IMPORTANT"
|
||||||
remoteassetsarchive "MyString"
|
remoteassetsarchive "MyString"
|
||||||
voiceoverselection "MyString"
|
voiceoverselection "MyString"
|
||||||
musicselection "MyString"
|
musicselection "MyString"
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe Admin do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
@ -1,5 +0,0 @@
|
|||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe User do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user