 
   describe "images" do
     alias Choicest.Collections.Image
+    alias Choicest.Collections.Collection
 
     @valid_image_attrs %{content_type: "some content_type", description: "some description", file_size: 42, filename: "some filename", url: "some url"}
     @update_image_attrs %{content_type: "some updated content_type", description: "some updated description", file_size: 43, filename: "some updated filename", url: "some updated url"}
     @invalid_image_attrs %{content_type: nil, description: nil, file_size: nil, filename: nil, url: nil}
 
-    def image_fixture(attrs \\ %{}) do
-      {:ok, image} =
+    @valid_collection_attrs %{description: "some description", name: "some name", voting_active: true}
+
+    def collection_fixture(attrs \\ %{}) do
+      {:ok, collection} =
         attrs
-        |> Enum.into(@valid_image_attrs)
-        |> Collections.create_image()
+        |> Enum.into(@valid_collection_attrs)
+        |> Collections.create_collection()
+
+      collection
+    end
+
+    def image_fixture(collection_id, attrs \\ %{}) do
+      attrs = attrs |> Enum.into(@valid_image_attrs)
+
+      {:ok, image} = Collections.create_image(collection_id, attrs)
 
       image
     end
 
-    def comparison_fixture() do
-      %Image{id: winner_id} = image_fixture()
-      %Image{id: loser_id} = image_fixture()
+    test "list_images/1 returns all images" do
+      %Collection{id: collection_id} = collection_fixture()
 
-      {:ok, comparison} = Collections.create_comparison(winner_id, loser_id)
-
-      comparison
+      image = image_fixture(collection_id)
+      assert Collections.list_images(collection_id) == [image]
     end
 
-    test "list_images/0 returns all images" do
-      image = image_fixture()
-      assert Collections.list_images() == [image]
+    test "get_image!/2 returns the image with given id" do
+      %Collection{id: collection_id} = collection_fixture()
+
+      image = image_fixture(collection_id)
+      assert Collections.get_image!(collection_id, image.id) == image
     end
 
-    test "get_image!/1 returns the image with given id" do
-      image = image_fixture()
-      assert Collections.get_image!(image.id) == image
-    end
+    test "create_image/2 with valid data creates a image" do
+      %Collection{id: collection_id} = collection_fixture()
 
-    test "create_image/1 with valid data creates a image" do
-      assert {:ok, %Image{} = image} = Collections.create_image(@valid_image_attrs)
+      assert {:ok, %Image{} = image} = Collections.create_image(collection_id, @valid_image_attrs)
       assert image.content_type == "some content_type"
       assert image.description == "some description"
       assert image.file_size == 42

      assert image.file_size == 43
      assert image.filename == "some updated filename"
      assert image.url == "some updated url"
    end

    test "update_image/2 with invalid data returns error changeset" do
      image = image_fixture()
      assert {:error, %Ecto.Changeset{}} = Collections.update_image(image, @invalid_image_attrs)
      assert image == Collections.get_image!(image.id)
    end

    test "delete_image/1 deletes the image" do
      image = image_fixture()
      assert {:ok, %Image{}} = Collections.delete_image(image)
      assert_raise Ecto.NoResultsError, fn -> Collections.get_image!(image.id) end
    end

    test "change_image/1 returns a image changeset" do
      image = image_fixture()
      assert %Ecto.Changeset{} = Collections.change_image(image)
    end
  end

    end

    test "create_image/1 with invalid data returns error changeset" do
      %Collection{id: collection_id} = collection_fixture()

      assert {:error, %Ecto.Changeset{}} = Collections.create_image(collection_id, @invalid_image_attrs)
    end

    test "update_image/2 with valid data updates the image" do
      %Collection{id: collection_id} = collection_fixture()

      image = image_fixture(collection_id)
      assert {:ok, image} = Collections.update_image(image, @update_image_attrs)
      assert %Image{} = image
      assert image.content_type == "some updated content_type"
