import Ember from "ember";
import { attr, Model } from "ember-cli-simple-store/model";
import { ValidationMixin, validate } from "ember-cli-simple-validation/mixins/validate";

var Person = Model.extend({
  name: attr()
});

var controller,
    container,
    model = Person.create({ name: "x" });

var FakeController = Ember.Controller.extend(ValidationMixin, {
  nameValidation: validate("model.name"),
  model: model
});

module("Unit: Validation Mixin", {
  setup: function () {
    container = new Ember.Container();
    container.register("controller:fake", FakeController);
    container.register("model:person", Person);
    controller = container.lookup("controller:fake");
  },
  teardown: function () {
    Ember.run(container, "destroy");
  }
});

test("validation will fire when computed validation value is update", function () {
  equal(controller.get("nameValidation"), true);
  model.set("name", "");
  equal(controller.get("nameValidation"), false);
});