Created
May 17, 2014 11:16
-
-
Save miyohide/cb7f09ef24c1fac412d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# itの中に puts @smith を加えると、それぞれのitのなかで返ってくる @smith オブジェクトは異なる。 | |
# ただし、puts @smith.inspectとするとそれぞれが同じ値を持っていて、同じオブジェクトのように思える。 | |
require 'spec_helper' | |
describe Contact do | |
# 省略 | |
describe "filter last name by letter" do | |
before :each do | |
@smith = Contact.create(firstname: 'John', lastname: 'Smith', | |
email: 'jsmith@example.com') | |
@jones = Contact.create(firstname: 'Tim', lastname: 'Jones', | |
email: 'tjones@example.com') | |
@johnson = Contact.create(firstname: 'John', lastname: 'Johnson', | |
email: 'jjohnson@example.com') | |
end | |
context "matching letters" do | |
it "returns a sorted array of results that match" do | |
puts @smith #=> #<Contact:0x007fe783380ff0> | |
puts @smith.inspect #=> #<Contact id: 4, firstname: "John", lastname: "Smith", email: "jsmith@example.com", created_at: "2014-05-17 11:14:12", updated_at: "2014-05-17 11:14:12"> | |
expect(Contact.by_letter("J")).to eq [@johnson, @jones] | |
end | |
end | |
context "non-matching letters" do | |
it "returns a sorted array of results that match" do | |
puts @smith #=> #<Contact:0x007fe780bf1f98> | |
puts @smith.inspect #=> #<Contact id: 4, firstname: "John", lastname: "Smith", email: "jsmith@example.com", created_at: "2014-05-17 11:14:12", updated_at: "2014-05-17 11:14:12"> | |
expect(Contact.by_letter("J")).to_not include @smith | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
puts @smith.inspect
として、同じ値が返ってくる理由は、log/test.log
をみるとよく分かる。分かりにくいんですが、
begin transaction
とrollback transaction
がそれぞれ2つずつあります。rollback transaction
はbegin transaction
からrollback transaction
の間で起きた変更をすべて元に戻す処理が行われます。このため、id
も含め、同じデータが返ってきます。