Skip to content

Commit

Permalink
Updates repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalimaha committed Apr 4, 2018
1 parent b787555 commit 109b57f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/repositories/updates_repository.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule WeatherStationManager.UpdatesRepositoryTest do
use WeatherStationManager.ModelCase

alias WeatherStationManager.{ Repo, Update, UpdatesRepository }

@update %{
:lat => 42.0,
:lon => 23.0,
:spam => "eggs",
:temperature => 100.0,
:station => "South Yarra"
}

test "save new content in the DB" do
UpdatesRepository.save(@update)

assert (length Repo.all Update) == 1
end

test "assigns an ID to the record" do
{ :ok, record } = UpdatesRepository.save(@update)

refute record.id == nil
end
end
12 changes: 12 additions & 0 deletions web/repositories/updates_repository.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule WeatherStationManager.UpdatesRepository do
alias WeatherStationManager.{ Repo, Update }

def find_all do
Repo.all(Update)
end

def save(update) do
Update.changeset(%Update{}, update)
|> Repo.insert
end
end

0 comments on commit 109b57f

Please sign in to comment.