Skip to content

Commit

Permalink
Merge pull request #180 from didacte/feature/frozen-regions
Browse files Browse the repository at this point in the history
Ensure regions cannot be modified outside gem
  • Loading branch information
j15e committed Jan 13, 2016
2 parents 2b4282e + 787d025 commit 5a5a5e7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/carmen/region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def name
end

def subregions
@subregions ||= load_subregions
@subregions ||= load_subregions.freeze
end

def subregions?
Expand Down
17 changes: 14 additions & 3 deletions spec/carmen/country_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@

describe Carmen::Country do

it "provides access to all countries" do
countries = Carmen::Country.all
countries.size.must_equal 3
describe "all" do
before do
@countries = countries = Carmen::Country.all
end

it "provides access to all countries" do
@countries.size.must_equal 3
end

it "denies modification of countries" do
assert_raises RuntimeError do
@countries.clear
end
end
end

describe "API for finding countries by name" do
Expand Down
10 changes: 10 additions & 0 deletions spec/carmen/region_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
end

describe "subregions" do
it "is frozen" do
subregions = Carmen::Country.coded('OC').subregions

assert_raises RuntimeError do
subregions.clear
end
end
end

describe "subregion" do
before do
@london = @airstrip_one.subregions.first
end
Expand Down

0 comments on commit 5a5a5e7

Please sign in to comment.