spec/integration_spec.rb in dm-parse-0.2.1 vs spec/integration_spec.rb in dm-parse-0.2.2
- old
+ new
@@ -1,14 +1,14 @@
require "spec_helper"
describe "resource" do
subject { resource }
- let(:resource) { model.new title: "Test Title", rank: 3, body: "Test Body" }
- let(:model) { Article }
+ let(:resource) { Article.new title: "Test Title", rank: 3, body: "Test Body" }
- before { model.all.destroy }
+ before { Article.all.destroy }
+ before { Comment.all.destroy }
it { should be_new }
it { should be_dirty }
its(:id) { should be_nil }
its(:created_at) { should be_nil }
@@ -21,39 +21,54 @@
it { should_not be_dirty }
its(:id) { should_not be_nil }
its(:created_at) { should_not be_nil }
its(:updated_at) { should_not be_nil }
end
+
+ context "when resource is a child" do
+ let(:resource) { Comment.create article: parent }
+ let(:parent) { Article.create }
+
+ its(:article) { should be(parent) }
+ end
end
describe "collection" do
subject { collection }
- let(:model) { Article }
- let(:collection) { model.all(:rank.gte => 5, :closed_at.gt => 1.day.from_now, :closed_at.lt => 3.days.from_now, :comments => { :body => /aa/im }) }
+ let(:collection) { Article.all(:rank.gte => 5, :closed_at.gt => 1.day.from_now, :closed_at.lt => 3.days.from_now, :comments => { :body => /aa/im }) }
- before { model.all.destroy }
+ before { Article.all.destroy }
before { Comment.all.destroy }
its(:size) { should eq(0) }
context "when resource in scope is saved" do
before do
- resource = model.create! rank: 5, closed_at: 2.day.from_now
+ resource = Article.create rank: 5, closed_at: 2.day.from_now
resource.comments.create body: "AA"
end
its(:size) { should eq(1) }
its(:count) { should eq(1) }
end
context "when resource out of scope is saved" do
- before { model.create rank: 4 }
+ before { Article.create rank: 4 }
its(:size) { should eq(0) }
its(:count) { should eq(0) }
end
+
+ context "when collection are children" do
+ let(:collection) { parent.comments }
+ let(:parent) { Article.create }
+ let!(:comment) { Comment.create article: parent }
+
+ its(:size) { should eq(1) }
+ its(:first) { should eq(comment) }
+ end
end
describe User do
subject { user }
@@ -101,14 +116,30 @@
subject { adapter }
let(:adapter) { DataMapper::Repository.adapters[:default] }
describe "#upload_file" do
- subject { adapter.upload_file filename, content }
+ subject { adapter.upload_file filename, content, content_type }
- let(:filename) { "xf x.txt" }
- let(:content) { "xx" }
+ let(:filename) { "xf x.txt" }
+ let(:content) { "xx" }
+ let(:content_type) { "plain/txt" }
it { should be_has_key("name") }
it { should be_has_key("url") }
+ end
+
+ describe "#request_password_reset" do
+ subject { adapter.request_password_reset email }
+
+ before do
+ repository :master do
+ User.all.destroy
+ end
+ end
+
+ let(:email) { user.email }
+ let(:user) { User.create! username: "a", password: "a", email: "a@abc.cn" }
+
+ it { should eq({}) }
end
end