Last active
December 20, 2015 06:48
-
-
Save okeen/6088458 to your computer and use it in GitHub Desktop.
wtf is wrong?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReportDownloadsController < InheritedResources::Base | |
actions :new, :create, :show | |
before_filter :build_report_download, except: :show | |
def create | |
if @report_download.save | |
ReportDownloadsMailer.sample_report_pdf_link(@report_download).deliver | |
render "thanks" | |
else | |
render "new" | |
end | |
end | |
def show | |
@report_download = ReportDownload.find_by_uuid(params[:id]) | |
redirect_to [:new, :report_download] if @report_download.blank? | |
@report_download.increment! :download_count | |
redirect_to @report_download.url | |
end | |
protected | |
def build_report_download | |
@report_download = ReportDownload.new params[:report_download] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe ReportDownloadsController do | |
describe 'on GET to new' do | |
before { get :new } | |
it { should render_template(:new) } | |
end | |
describe 'on POST to create' do | |
context "with valid email and name" do | |
before { post :create, report_download: { name: "ACME", email: "[email protected]" }, lang: :en } | |
it { should assign_to(:report_download) } | |
it { should render_template(:thanks) } | |
end | |
context "with invalid data" do | |
before { post :create, report_download: { name: "ACME", email: "" }, lang: :en } | |
it { should assign_to(:report_download) } | |
it { should render_template(:new) } | |
end | |
end | |
describe 'on GET to show' do | |
context "with a valid UUID" do | |
before do | |
@report_download = create :report_download | |
get :show, id: @report_download.id, lang: :en | |
end | |
it { should assign_to(:report_download) } | |
it "should add a download to the count" do | |
@report_download.download_count.should eq 1 | |
end | |
it { should redirect_to( [@report_download] ) } | |
end | |
context "with an invalid UUID" do | |
before { get :show, id: "UNEXISTING_UUID", lang: :en } | |
it { should redirect_to( [:new, :report_download] ) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment