Skip to content

Commit

Permalink
Merge e647e64 into 6e00856
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed Nov 24, 2018
2 parents 6e00856 + e647e64 commit 20f4e5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 13 additions & 1 deletion lib/ayashige/application.rb
Expand Up @@ -15,7 +15,19 @@ class Application < Sinatra::Base
get "/feed" do
content_type :json

Store.all.to_json
array = []
data = Store.all
data.each do |key, values|
values.each do |value|
domain = Domain.new(value)
array << {
domain: domain.to_s,
score: domain.score,
created: key
}
end
end
array.to_json
end
end
end
11 changes: 7 additions & 4 deletions spec/application_spec.rb
Expand Up @@ -20,16 +20,19 @@ def app
describe "GET /feed" do
before do
allow(Ayashige::Store).to receive(:all).and_return(
"2018-01-01": ["test.com", "example.com"]
"2018-01-01": ["paypal.pay.pay.com", "google.apple.microsoft.com"]
)
end

it "should return 200 OK" do
get "/feed"
expect(last_response).to be_ok
json = JSON.parse(last_response.body.to_s)
expect(json).to be_a(Hash)
expect(json.keys).to eq(["2018-01-01"])
array = JSON.parse(last_response.body.to_s)
expect(array).to be_a(Array)
first = array.first
expect(first["domain"]).to eq("paypal.pay.pay.com")
expect(first["created"]).to eq("2018-01-01")
expect(first["score"]).to be_an(Integer)
end
end
end

0 comments on commit 20f4e5f

Please sign in to comment.