Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add reload API #16

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
rate_center (0.1.2)
rate_center (0.1.4)

GEM
remote: https://rubygems.org/
Expand Down
4 changes: 4 additions & 0 deletions lib/rate_center/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def collection
@collection ||= load_collection
end

def reload!
@collection = load_collection
end

def all
collection
end
Expand Down
14 changes: 14 additions & 0 deletions spec/city_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ module RateCenter
)
end

it "reloads the data" do
::RateCenter.load(:cities, only: { us: { ny: "New York", ca: "Los Angeles" } })

cities = City.all

expect(cities.size).to eq(2)

::RateCenter.load(:cities, only: { us: { ny: "New York", ca: [ "San Francisco", "Los Angeles" ] } })
expect(cities.size).to eq(2)

City.reload!
expect(City.all.size).to eq(3)
end

it "finds a city" do
::RateCenter.load(:cities, only: { us: { ny: "New York" } })

Expand Down