spec/findable/base_spec.rb in findable-0.1.3 vs spec/findable/base_spec.rb in findable-0.1.4
- old
+ new
@@ -69,7 +69,68 @@
model.create(name: "example")
}.to change { model.count }.by(1)
}
it { expect(model).to respond_to(:create!) }
end
-end
+ # Query APIs
+ describe ".exists?" do
+ let!(:persisted_object) { model.create(name: name) }
+
+ it { expect(model.exists?(persisted_object)).to be_truthy }
+ it { expect(model.exists?(persisted_object.id)).to be_truthy }
+ it { expect(model.exists?(nil)).to be_falsey }
+ end
+
+ describe ".insert" do
+ let(:new_object) { model.new(name: name) }
+
+ it {
+ expect {
+ model.insert(new_object)
+ }.to change { model.query.count }.by(1)
+ }
+ end
+
+ describe ".delete" do
+ let!(:persisted_object) { model.create(name: name) }
+
+ it {
+ expect {
+ model.delete(persisted_object)
+ }.to change { model.query.count }.by(-1)
+ }
+ end
+
+ # Instance methods
+ describe "#id=" do
+ it {
+ instance.id = id
+ expect(instance.attributes[:id]).to eq(id)
+ }
+ end
+
+ describe "#hash" do
+ let!(:persisted_object) { model.create(name: name) }
+ it { expect(persisted_object.hash).to eq(persisted_object.id.hash) }
+ end
+
+ describe "#delete" do
+ let!(:persisted_object) { model.create(name: name) }
+ it {
+ expect {
+ persisted_object.delete
+ }.to change { model.query.count }.by(-1)
+ }
+ end
+
+ # Private instance methods
+ describe "#attribute=" do
+ before { instance.send(:attribute=, :example, "value") }
+ it { expect(instance.attributes[:example]).to eq("value") }
+ end
+
+ describe "#attribute?" do
+ before { instance.send(:attribute=, :example, "value") }
+ it { expect(instance.send(:attribute?, :example)).to be_truthy }
+ end
+end