Commit 7bd5c3f5ccaaed216e3b5a7e2a66cb1776803a83
Committed by
Daniela Feitosa
1 parent
6da1fe92
Exists in
staging
and in
42 other branches
Fix use of google static map api v3
Also move view to template
Showing
4 changed files
with
31 additions
and
19 deletions
Show diff stats
app/models/location_block.rb
| 1 | 1 | class LocationBlock < Block |
| 2 | 2 | |
| 3 | - settings_items :zoom, :type => :integer , :default => 4 | |
| 4 | - settings_items :map_type, :type => :string , :default => 'roadmap' | |
| 3 | + settings_items :zoom, :type => :integer, :default => 4 | |
| 4 | + settings_items :map_type, :type => :string, :default => 'roadmap' | |
| 5 | 5 | |
| 6 | 6 | def self.description |
| 7 | 7 | _('Location map') |
| ... | ... | @@ -12,18 +12,10 @@ class LocationBlock < Block |
| 12 | 12 | end |
| 13 | 13 | |
| 14 | 14 | def content(args={}) |
| 15 | + block = self | |
| 15 | 16 | profile = self.owner |
| 16 | - title = self.title | |
| 17 | - if profile.lat | |
| 18 | - block_title(title) + | |
| 19 | - content_tag('div', | |
| 20 | - '<img src="http://maps.google.com/maps/api/staticmap?center=' + profile.lat.to_s() + | |
| 21 | - ',' + profile.lng.to_s() + '&zoom=' + zoom.to_s() + | |
| 22 | - '&size=190x250&maptype=' + map_type + '&markers=' + profile.lat.to_s() + ',' + | |
| 23 | - profile.lng.to_s() + ',green' + '&sensor=false"/>', | |
| 24 | - :class => 'the-localization-map' ) | |
| 25 | - else | |
| 26 | - content_tag('i', _('This profile has no geographical position registered.')) | |
| 17 | + lambda do | |
| 18 | + render :file => 'blocks/location', :locals => {:block => block, :profile => profile} | |
| 27 | 19 | end |
| 28 | 20 | end |
| 29 | 21 | ... | ... |
| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | +<% if profile.lat %> | |
| 2 | + <%= block_title block.title %> | |
| 3 | + <div class='the-localization-map'> | |
| 4 | + <img src="http://maps.google.com/maps/api/staticmap?center=<%=profile.lat%>,<%=profile.lng%>&zoom=<%=block.zoom%>&size=190x250&maptype=<%=block.map_type%>&markers=<%=profile.lat%>,<%=profile.lng%>&sensor=false"/> | |
| 5 | + </div> | |
| 6 | +</div> | |
| 7 | +<% else %> | |
| 8 | + <i><%= _('This profile has no geographical position registered.') %></i> | |
| 9 | +<% end %> | ... | ... |
test/test_helper.rb
| ... | ... | @@ -79,7 +79,7 @@ class ActiveSupport::TestCase |
| 79 | 79 | |
| 80 | 80 | destname = 'test_should_' + name.gsub(/[^a-zA-z0-9]+/, '_') |
| 81 | 81 | if @shoulds.include?(destname) |
| 82 | - raise "there is already a test named \"#{destname}\"" | |
| 82 | + raise "there is already a test named \"#{destname}\"" | |
| 83 | 83 | end |
| 84 | 84 | |
| 85 | 85 | @shoulds << destname |
| ... | ... | @@ -121,7 +121,7 @@ class ActiveSupport::TestCase |
| 121 | 121 | object.valid? |
| 122 | 122 | assert !object.errors.invalid?(attribute) |
| 123 | 123 | end |
| 124 | - | |
| 124 | + | |
| 125 | 125 | def assert_subclass(parent, child) |
| 126 | 126 | assert_equal parent, child.superclass, "Class #{child} expected to be a subclass of #{parent}" |
| 127 | 127 | end |
| ... | ... | @@ -150,7 +150,7 @@ class ActiveSupport::TestCase |
| 150 | 150 | get action, params |
| 151 | 151 | end |
| 152 | 152 | doc = Hpricot @response.body |
| 153 | - | |
| 153 | + | |
| 154 | 154 | # Test style references: |
| 155 | 155 | (doc/'style').each do |s| |
| 156 | 156 | s = s.to_s().gsub( /\/\*.*\*\//, '' ). |
| ... | ... | @@ -193,6 +193,12 @@ class ActiveSupport::TestCase |
| 193 | 193 | assert !tag, "expected no tag #{options.inspect}, but tag found in #{text.inspect}" |
| 194 | 194 | end |
| 195 | 195 | |
| 196 | + # For models that render views (blocks, articles, ...) | |
| 197 | + def render(*args) | |
| 198 | + view_paths = @explicit_view_paths || ActionController::Base.view_paths | |
| 199 | + ActionView::Base.new(view_paths, {}).render(*args) | |
| 200 | + end | |
| 201 | + | |
| 196 | 202 | private |
| 197 | 203 | |
| 198 | 204 | def uses_host(name) | ... | ... |
test/unit/location_block_test.rb
| ... | ... | @@ -2,6 +2,9 @@ require File.dirname(__FILE__) + '/../test_helper' |
| 2 | 2 | |
| 3 | 3 | class LocationBlockTest < ActiveSupport::TestCase |
| 4 | 4 | |
| 5 | + ActionView::Base.send :include, BlockHelper | |
| 6 | + include BoxesHelper | |
| 7 | + | |
| 5 | 8 | def setup |
| 6 | 9 | @profile = create_user('lele').person |
| 7 | 10 | @block = LocationBlock.new |
| ... | ... | @@ -15,7 +18,7 @@ class LocationBlockTest < ActiveSupport::TestCase |
| 15 | 18 | end |
| 16 | 19 | |
| 17 | 20 | should 'display no localization map without lat' do |
| 18 | - assert_tag_in_string block.content, :tag => 'i' | |
| 21 | + assert_tag_in_string extract_block_content(block.content), :tag => 'i' | |
| 19 | 22 | end |
| 20 | 23 | |
| 21 | 24 | should 'be editable' do |
| ... | ... | @@ -28,8 +31,10 @@ class LocationBlockTest < ActiveSupport::TestCase |
| 28 | 31 | |
| 29 | 32 | should 'use google maps api v3' do |
| 30 | 33 | @block.owner.lat = '-12.34'; @block.owner.save! |
| 31 | - assert_match 'http://maps.google.com/maps/api/staticmap', @block.content | |
| 32 | - assert_no_match /key=/, @block.content | |
| 34 | + content = extract_block_content(@block.content) | |
| 35 | + | |
| 36 | + assert_match 'http://maps.google.com/maps/api/staticmap', content | |
| 37 | + assert_no_match /key=/, content | |
| 33 | 38 | end |
| 34 | 39 | |
| 35 | 40 | end | ... | ... |