Skip to content

Commit b93d7cd

Browse files
committed
also set default tile sources when updating the project.
- this has the side effect that a project with the gtt module enabled can never have _no_ tile sources configured (since an empty set will be replaced with the defaults).
1 parent 9608296 commit b93d7cd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/redmine_gtt/patches/project_patch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def self.apply
88
Project.class_eval do
99
safe_attributes "geom"
1010
has_and_belongs_to_many :gtt_tile_sources
11-
after_create :set_default_tile_sources
11+
after_save :set_default_tile_sources
1212
end
1313
end
1414
end

test/unit/update_project_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require_relative '../test_helper'
2+
3+
class UpdateProjectTest < ActiveSupport::TestCase
4+
5+
test 'should add default tile source if module is enabled' do
6+
ts = RedmineGtt::Actions::CreateTileSource.(type: 'ol.source.OSM', name: 'default', default: true).tile_source
7+
RedmineGtt::Actions::CreateTileSource.(type: 'ol.source.OSM', name: 'not default', default: false)
8+
9+
p = Project.create! name: 'test project', identifier: 'test-project'
10+
assert p.gtt_tile_sources.none? # module not enabled
11+
12+
p.update_attribute :enabled_module_names, ['gtt']
13+
p.reload
14+
assert_equal [ts], p.gtt_tile_sources.to_a
15+
end
16+
17+
end
18+
19+

0 commit comments

Comments
 (0)