Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
fix OWMW space replacement issue, closes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesisdesign committed Jun 23, 2014
1 parent 7ae0b03 commit 74cb0e4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def update
when 'boolean'
Configuration.set(key, content[:value], 'boolean')
when 'array'
Configuration.set(key, content[:value].gsub(/ /,"-").gsub(/,/,"\n"), 'array')
Configuration.set(key, content[:value], 'array')
end
end

Expand Down
14 changes: 12 additions & 2 deletions app/models/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ class Configuration < ActiveRecord::Base
def self.get(key)
value = AppConfig[key]
raise("BUG: value for key #{key} not found!") if value.nil?


if value.class == Array and value.length == 1 and value[0].include?(',')
value = value[0].split(',')
end

value
end

def self.set(key, value, format, description = nil)
def self.set(key, value, format, description=nil)
key = key.to_s
value = value.to_s
format = format.to_s

if format == 'array'
# if format is array
# use comma separator without space, convert space between words with dashes
value = value.gsub(', ', ',').gsub(/ /,"-").downcase
end

begin
AppConfig.set_key(key, value, format)
Expand Down
40 changes: 37 additions & 3 deletions test/unit/configuration_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
require 'test_helper'

class ConfigurationTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
test "get" do
c = Configuration.get('wisps_with_owmw')
assert_equal Array, c.class
assert_equal 0, c.length
end

test "set" do
Configuration.set('wisps_with_owmw', 'test1', 'array')
c = Configuration.get('wisps_with_owmw')
assert_equal Array, c.class
assert_equal 1, c.length
assert_equal 'test1', c[0]

Configuration.set('wisps_with_owmw', 'test1, test2', 'array')
c = Configuration.get('wisps_with_owmw')
assert_equal Array, c.class
assert_equal 2, c.length
assert_equal 'test1', c[0]
assert_equal 'test2', c[1]

Configuration.set('wisps_with_owmw', 'one,two,three', 'array')
c = Configuration.get('wisps_with_owmw')
assert_equal Array, c.class
assert_equal 3, c.length
assert_equal 'one', c[0]
assert_equal 'two', c[1]
assert_equal 'three', c[2]
end

test "slugify" do
Configuration.set('wisps_with_owmw', 'Test Slug, Another One,Do It', 'array')
c = Configuration.get('wisps_with_owmw')
assert_equal c.class, Array
assert_equal c.length, 3
assert_equal 'test-slug', c[0]
assert_equal 'another-one', c[1]
assert_equal 'do-it', c[2]
end
end
13 changes: 13 additions & 0 deletions test/unit/wisp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,17 @@ class WispTest < ActiveSupport::TestCase
assert_equal 2, wisp.count_access_points(:total)
assert_equal 0, wisp.count_access_points(:favourite)
end

test "owmw_enabled" do
Wisp.all.each do |wisp|
assert_equal false, wisp.owmw_enabled?
end

Configuration.set('owmw_enabled', true, 'boolean')
Configuration.set('wisps_with_owmw', 'provinciawifi, freewifi brescia, small wisp', 'array')

Wisp.all.each do |wisp|
assert_equal true, wisp.owmw_enabled?
end
end
end

0 comments on commit 74cb0e4

Please sign in to comment.