spec/findable/query_spec.rb in findable-0.1.4 vs spec/findable/query_spec.rb in findable-0.1.5
- old
+ new
@@ -5,12 +5,12 @@
include_context "ReadOnlyModel"
let(:auto_increment_key) { Findable::Query::Namespace::AUTO_INCREMENT_KEY }
describe "#data" do
- it { expect(read_model.query.data).to be_kind_of(Array) }
- it { expect(read_model.query.data.size).to eq(1) }
+ it { expect(read_model.query.all).to be_kind_of(Array) }
+ it { expect(read_model.query.all.size).to eq(1) }
end
describe "#ids" do
it { expect(read_model.query.ids).to be_kind_of(Array) }
it { expect(read_model.query.ids).to eq([1]) }
@@ -19,49 +19,48 @@
describe "#count" do
it { expect(read_model.query.count).to eq(1) }
end
describe "#find_by_ids" do
- let(:raw_value) { read_model.query.find_by_ids(1) }
- let(:loaded_value) { Oj.load(raw_value.first) }
+ let(:data) { read_model.query.find_by_ids(1) }
- it { expect(raw_value).to be_kind_of(Array) }
- it { expect(raw_value.first).to be_kind_of(String) }
- it { expect(loaded_value[:id]).to eq(1) }
+ it { expect(data).to be_kind_of(Array) }
+ it { expect(data.first).to be_kind_of(read_model) }
+ it { expect(data.first.id).to eq(1) }
end
describe "#exists?" do
it { expect(read_model.exists?(1)).to be_truthy }
it { expect(read_model.exists?(2)).to be_falsey }
end
describe "#insert" do
- it { expect(model.query.insert(name: name)).to be_kind_of(Hash) }
- it { expect(model.query.insert(name: name)[:id]).not_to be_nil }
- it { expect(model.query.insert(name: name)[:name]).to eq(name) }
+ it { expect(model.create(name: name)).to be_kind_of(model) }
+ it { expect(model.create(name: name).id).not_to be_nil }
+ it { expect(model.create(name: name).name).to eq(name) }
it {
expect {
- model.query.insert(name: name)
+ model.create(name: name)
}.to change { model.query.count }.by(1)
}
end
describe "#import" do
end
describe "#delete" do
- let!(:params) { model.query.insert(name: name) }
+ let!(:persisted_object) { model.create(name: name) }
it {
expect {
- model.query.delete(params[:id])
+ model.query.delete(persisted_object.id)
}.to change { model.query.count }.by(-1)
}
end
describe "#delete_all" do
before {
- model.query.insert(name: name)
+ model.create(name: name)
model.query.delete_all
}
it { expect(model.query.redis.exists(model.query.data_key)).to be_falsey }
it { expect(model.query.redis.exists(model.query.info_key)).to be_falsey }