Skip to content

Commit

Permalink
config specs
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed Oct 12, 2012
1 parent fe5c8d8 commit 5ba6486
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/gmaps4rails/base.rb
Expand Up @@ -8,6 +8,7 @@ module Gmaps4rails
require 'gmaps4rails/extensions/enumerable'
require 'gmaps4rails/extensions/hash'

autoload :Config, 'gmaps4rails/config'
autoload :ModelHandler, 'gmaps4rails/model_handler'
autoload :ActsAsGmappable, 'gmaps4rails/acts_as_gmappable'

Expand Down
2 changes: 1 addition & 1 deletion lib/gmaps4rails/helper/gmaps4rails_helper.rb
Expand Up @@ -13,7 +13,7 @@ def gmaps4rails(builder)
# full helper to pass all variables and their options
# @params [Hash] options is a Hash containing data and options. Example: { markers:{ data: @json, options: { do_clustering: true } } }
def gmaps(options = {})
options = Gmaps4rails.config.load.merge(options)
options = Gmaps4rails.config.options.merge(options)

gmaps_libs(options) if options[:with_libs]

Expand Down
6 changes: 6 additions & 0 deletions spec/dummy/config/gmaps4rails.yml
@@ -0,0 +1,6 @@
map_options:
provider: mapquest
provider_key: 12345
auto_adjust: true
center_on_user: true
zoom: 5
55 changes: 55 additions & 0 deletions spec/lib/config_spec.rb
@@ -0,0 +1,55 @@
require 'spec_helper'


class Configuration
include Gmaps4railsHelper
end

describe Gmaps4rails::Config::YamlLoader do
subject { Gmaps4rails::Config::YamlLoader.new }

it 'should load a Hash from config file' do
subject.load.should be_a Hash
end

it 'should have a config_file' do
subject.config_file.should == 'gmaps4rails.yml'
end

it 'should have a config_path' do
subject.config_path.to_s.should include('spec/dummy/config/gmaps4rails.yml')
end

describe '#config_file = ' do
let(:config_file) { 'gmaps.yml' }

before :each do
subject.config_file = config_file
end

it 'should set it' do
subject.config_file.should == config_file
end

it 'should load an empty Hash if no matching config file' do
subject.load.should == {}
end
end
end

describe Gmaps4rails::Config do
subject { Gmaps4rails.config }

it 'should have a yaml loader' do
subject.send(:yaml_loader).should be_a Gmaps4rails::Config::YamlLoader
end

it 'should load options from yaml file' do
subject.options.should be_a Hash
subject.options.should_not be_empty
end

it 'should load provider map_options from yaml file' do
subject.options[:map_options][:provider].should == 'mapquest'
end
end

0 comments on commit 5ba6486

Please sign in to comment.