Skip to content

Commit

Permalink
convert helper specs to request specs
Browse files Browse the repository at this point in the history
as the new api involves content_for :javscripts
  • Loading branch information
Phil Lee committed Jul 16, 2014
1 parent c2f1645 commit 16efe8a
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 39 deletions.
8 changes: 8 additions & 0 deletions spec/dummy/app/controllers/frontend_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
class FrontendController < ApplicationController
def index
end

def with_config
end

def without_config
end

def called_twice
end
end
1 change: 1 addition & 0 deletions spec/dummy/app/views/frontend/called_twice.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= zendesk_feedback_tab({en: {id: 1, url: 2}}) + zendesk_feedback_tab({en: {id: 1, url: 2}}) %>
1 change: 1 addition & 0 deletions spec/dummy/app/views/frontend/with_config.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= zendesk_feedback_tab({en: {id: 1, url: 2}}) %>
1 change: 1 addition & 0 deletions spec/dummy/app/views/frontend/without_config.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= zendesk_feedback_tab(nil) %>
3 changes: 3 additions & 0 deletions spec/dummy/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Rails.application.routes.draw do
scope "/:locale", :locale => /en|cy/ do
get '/frontend', to: 'frontend#index', format: false
get '/frontend/with_config', to: 'frontend#with_config'
get '/frontend/without_config', to: 'frontend#without_config'
get '/frontend/called_twice', to: 'frontend#called_twice'
end
end
39 changes: 0 additions & 39 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,6 @@
module Zendesk
module Feedback
describe ApplicationHelper, type: :helper do
describe '#zenbox_feedback_tab' do
subject(:output) { helper.zendesk_feedback_tab(config) }

context 'config present' do
let(:config) { double(:[] => { id: 1, url: 2 }) }

it 'includes the dropbox id' do
expect(output).to match(/dropboxID\:\s*"1"/)
end

it 'includes the dropbox url' do
expect(output).to match(/url\:\s*"2"/)
end
end

describe 'config missing' do
["", nil, [], {}].each do |missing|
context "blank with #{missing.inspect}" do
let(:config) { missing }

it 'returns blank' do
expect(output).to be_blank
end
end
end
end

describe 'being called twice' do
let(:config) { double(:[] => { id: 1, url: 2 }) }

it 'should not initialize twice' do
output = helper.zendesk_feedback_tab(config) + helper.zendesk_feedback_tab(config)

expect(output).to_not match(/dropboxID\:\s*"1".*dropboxID\:\s*"1"/)
expect(output).to_not match(/url\:\s*"2".*url\:\s*"2"/)
end
end

end
end
end
end
31 changes: 31 additions & 0 deletions spec/requests/feedback_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'spec_helper'

describe 'Feedback', type: :request do
context 'when config is present' do
it 'includes dropbox id' do
get '/en/frontend/with_config'
expect(response.body).to match(/dropboxID\:\s*"1"/)
end

it 'includes the dropbox url' do
get '/en/frontend/with_config'
expect(response.body).to match(/url\:\s*"2"/)
end
end

context "config is blank" do
it 'does not include script' do
get '/en/frontend/without_config'
expect(response.body).to_not include('script')
end
end

context 'called twice' do
it 'should not initialize twice' do
get '/en/frontend/called_twice'

expect(response.body).to_not match(/dropboxID\:\s*"1".*dropboxID\:\s*"1"/)
expect(response.body).to_not match(/url\:\s*"2".*url\:\s*"2"/)
end
end
end

0 comments on commit 16efe8a

Please sign in to comment.