Permalink
Browse files

Fix all ecto warnings

  • Loading branch information...
vanstee committed Jun 29, 2016
1 parent 0c6968f commit 1d6d7be8d08a60f828f0a2d43cf625730054b5de
View
@@ -147,8 +147,8 @@ get the command working.
```elixir
command = Repo.insert!(%Command{name: "add", version: "0.0.1"})
Repo.insert!(Ecto.Model.build(command, :args, name: "left", rank: 0))
Repo.insert!(Ecto.Model.build(command, :args, name: "right", rank: 1))
Repo.insert!(Ecto.build_assoc(command, :args, name: "left", rank: 0))
Repo.insert!(Ecto.build_assoc(command, :args, name: "right", rank: 1))
```
3. Create permissions and rules
@@ -160,12 +160,12 @@ get the command working.
```elixir
# Create permission
namespace = Repo.insert!(%Namespace{name: "add"})
permission = Repo.insert!(Ecto.Model.build(namespace, :permissions, name: "read"))
permission = Repo.insert!(Ecto.build_assoc(namespace, :permissions, name: "read"))
# Create rule for permission
rule = "when command is add must have add:read"
{:ok, parse_tree} = Permissions.Parser.parse(rule)
Repo.insert!(Ecto.Model.build(command, :rules, parse_tree: parse_tree))
Repo.insert!(Ecto.build_assoc(command, :rules, parse_tree: parse_tree))
# Grant permission to user
Repo.insert!(%UserPermission{user_id: user.id, permission: permission.id})
@@ -28,7 +28,7 @@ defmodule Cog.Models.Command do
"""
def build_new(%Bundle{id: _}=bundle, params) do
bundle
|> Ecto.Model.build(:commands)
|> Ecto.build_assoc(:commands)
|> changeset(params)
end
@@ -59,7 +59,7 @@ defmodule Cog.Models.CommandOption do
"""
def build_new(%CommandVersion{}=command, params) do
command
|> Ecto.Model.build(:options)
|> Ecto.build_assoc(:options)
|> changeset(params)
end
@@ -31,7 +31,7 @@ defmodule Cog.Models.CommandVersion do
"""
def build_new(%BundleVersion{id: _}=bundle_version, params) do
bundle_version
|> Ecto.Model.build(:command_versions)
|> Ecto.build_assoc(:command_versions)
|> changeset(params)
end
@@ -25,7 +25,7 @@ defmodule Cog.Models.Permission do
"""
def build_new(%Bundle{}=bundle, params) do
bundle
|> Ecto.Model.build(:permissions)
|> Ecto.build_assoc(:permissions)
|> changeset(params)
end
View
@@ -33,7 +33,7 @@ defmodule Cog.Models.Rule do
end
def insert_new(%Command{}=command, params) do
command
|> Ecto.Model.build(:rules, params)
|> Ecto.build_assoc(:rules, params)
|> changeset(params)
|> Repo.insert
end
View
@@ -21,7 +21,7 @@ defmodule Cog.Models.Token do
"""
def insert_new(%User{}=user, params) do
user
|> Ecto.Model.build(:tokens, params)
|> Ecto.build_assoc(:tokens, params)
|> changeset(params)
|> Repo.insert
end
@@ -593,7 +593,7 @@ defmodule Cog.Repository.Bundles do
defp new_version!(bundle, params) do
bundle
|> Ecto.Model.build(:versions)
|> Ecto.build_assoc(:versions)
|> BundleVersion.changeset(params)
|> Repo.insert!
|> preload
@@ -683,7 +683,7 @@ defmodule Cog.Repository.Bundles do
canonical_command = Enum.find(all_commands, &(&1.name == command_name))
command_version = bundle_version
|> Ecto.Model.build(:commands)
|> Ecto.build_assoc(:commands)
|> Map.put(:command_id, canonical_command.id)
|> CommandVersion.changeset(command_spec)
|> Repo.insert!
@@ -715,7 +715,7 @@ defmodule Cog.Repository.Bundles do
}
bundle_version
|> Ecto.Model.build(:templates)
|> Ecto.build_assoc(:templates)
|> Template.changeset(params)
|> Repo.insert!
end)
@@ -780,7 +780,7 @@ defmodule Cog.Repository.Bundles do
defp add_bundle_command(bundle, command_name) do
bundle
|> Ecto.Model.build(:commands)
|> Ecto.build_assoc(:commands)
|> Command.changeset(%{name: command_name})
|> Repo.insert!
end
@@ -41,7 +41,7 @@ defmodule Cog.Repository.Permissions do
"""
def create_permission(bundle_version, permission_name) do
case bundle_version.bundle
|> Ecto.Model.build(:permissions)
|> Ecto.build_assoc(:permissions)
|> Permission.changeset(%{name: permission_name})
|> Repo.insert do
{:ok, permission} ->
@@ -1,8 +1,6 @@
defmodule Cog.Repo.Migrations.AddSshAdapter do
use Ecto.Migration
alias Cog.Repo
def up do
execute """
INSERT INTO chat_providers ( name, inserted_at, updated_at )
@@ -1,7 +1,5 @@
defmodule Cog.Repo.Migrations.InsertFallbackTemplates do
use Ecto.Migration
alias Cog.Models.Template
alias Cog.Repo
def change do
# That extra newline is there for a reason. Mustache spec strips newlines
@@ -1,7 +1,5 @@
defmodule Cog.Repo.Migrations.InsertErrorTemplates do
use Ecto.Migration
alias Cog.Models.Template
alias Cog.Repo
def change do
@@ -1,7 +1,5 @@
defmodule Cog.Repo.Migrations.AddVersionToBundles do
use Ecto.Migration
alias Cog.Repo
alias Cog.Models.Bundle
def change do
alter table(:bundles) do
@@ -7,6 +7,9 @@ defmodule Cog.Command.Service.MemoryTest do
@token "d386da42-0c99-11e6-aa1c-db55971236aa"
setup_all do
Ecto.Adapters.SQL.Sandbox.checkout(Cog.Repo)
Ecto.Adapters.SQL.Sandbox.mode(Cog.Repo, {:shared, self()})
pid = Process.whereis(Memory)
Process.unregister(Memory)
@@ -3,15 +3,15 @@ defmodule Cog.Models.EctoJson.Test do
alias Cog.Models.EctoJson
defmodule NoJsonTest do
use Ecto.Model
use Ecto.Schema
schema "nope" do
field :reason, :string
end
end
defmodule ScalarTest do
use Ecto.Model
use Ecto.Schema
use Cog.Models.EctoJson
schema "testing" do
@@ -26,7 +26,7 @@ defmodule Cog.Models.EctoJson.Test do
end
defmodule MultiTest do
use Ecto.Model
use Ecto.Schema
use Cog.Models.EctoJson
schema "multi" do

0 comments on commit 1d6d7be

Please sign in to comment.