Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor big helper to partial and smaller helper. [#82]
- Loading branch information
Showing
5 changed files
with
37 additions
and
68 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module GmapsHelper | ||
def gmaps_api_key | ||
GMAPS_API_KEY.kind_of?(Hash) ? GMAPS_API_KEY[controller.request.host_with_port] : GMAPS_API_KEY | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
= event_map @event, @host | ||
- content_for(:javascript) do | ||
= javascript_include_tag "http://maps.google.com/maps?file=api&v=2&sensor=false&key=#{gmaps_api_key}" | ||
= javascript_include_tag('events/map') | ||
|
||
= info(@event) | ||
#lat.hidden= @event.latitude | ||
#lng.hidden= @event.longitude | ||
#map |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'spec_helper.rb' | ||
|
||
describe GmapsHelper do | ||
describe '.gmaps_api_key' do | ||
let(:key) { Faker::Lorem.sentence.gsub /\s/, '_' } | ||
|
||
context 'API key is a string' do | ||
it 'should return the string' do | ||
stub_const 'GMAPS_API_KEY', key | ||
helper.gmaps_api_key.should == key | ||
end | ||
end | ||
|
||
context 'API key is a hash' do | ||
it 'should use the hostname as a key into the hash' do | ||
hostname = "#{Faker::Internet.domain_name}:#{rand 10000}" | ||
controller.stub_chain(:request, :host_with_port).and_return hostname | ||
stub_const 'GMAPS_API_KEY', {hostname => key, 'other-host.com' => 'some_other_key'} | ||
|
||
helper.gmaps_api_key.should == key | ||
end | ||
end | ||
end | ||
end |