Objects are immutable when they've been deleted or frozen for some reason. Deleting a record from your data store will always result in that record being frozen.
Is there a specific problem that you're having?
-T
On Mon, Jan 10, 2011 at 10:23 AM, Zhi-Qiang Lei <zhiqiang....@gmail.com>wrote:
> Could anyone answer me when a resource should be immutable? And why? > Thanks.
> Best regards, > Zhi-Qiang Lei > zhiqiang....@gmail.com
> -- > You received this message because you are subscribed to the Google Groups > "DataMapper" group. > To post to this group, send email to datamapper@googlegroups.com. > To unsubscribe from this group, send email to > datamapper+unsubscribe@googlegroups.com<datamapper%2Bunsubscribe@googlegrou ps.com> > . > For more options, visit this group at > http://groups.google.com/group/datamapper?hl=en.
> Could anyone answer me when a resource should be immutable? And why? Thanks.
> Best regards, > Zhi-Qiang Lei > zhiqiang....@gmail.com
> -- > You received this message because you are subscribed to the Google Groups "DataMapper" group. > To post to this group, send email to datamapper@googlegroups.com. > To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
On Mon, Jan 10, 2011 at 16:39, Jonathan Stott <jonathan.st...@gmail.com> wrote: > Also, you will retreive an immutable resource if you define a Model > without a key.
> To check for this (and to initialize relationships), you should always > run DataMapper.finalize after defining all your models.
> Regards > Jon
> On 10 January 2011 15:23, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >> Dear All,
>> Could anyone answer me when a resource should be immutable? And why? Thanks.
>> Best regards, >> Zhi-Qiang Lei >> zhiqiang....@gmail.com
>> -- >> You received this message because you are subscribed to the Google Groups "DataMapper" group. >> To post to this group, send email to datamapper@googlegroups.com. >> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >> For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
> -- > You received this message because you are subscribed to the Google Groups "DataMapper" group. > To post to this group, send email to datamapper@googlegroups.com. > To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
On Mon, Jan 10, 2011 at 16:52, Martin Gamsjaeger <gamsnj...@gmail.com> wrote: > To add to what Jonathan said, if you *retrieve* a resource without > it's key, you get back an immutable resource too.
> So if you have a Person model with a Serial id and you do something like:
> you will get back a Collection of immutable resources, because you've > told it specifically to not include the key property (:id)
> cheers > snusnu
> On Mon, Jan 10, 2011 at 16:39, Jonathan Stott <jonathan.st...@gmail.com> wrote: >> Also, you will retreive an immutable resource if you define a Model >> without a key.
>> To check for this (and to initialize relationships), you should always >> run DataMapper.finalize after defining all your models.
>> Regards >> Jon
>> On 10 January 2011 15:23, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >>> Dear All,
>>> Could anyone answer me when a resource should be immutable? And why? Thanks.
>>> Best regards, >>> Zhi-Qiang Lei >>> zhiqiang....@gmail.com
>>> -- >>> You received this message because you are subscribed to the Google Groups "DataMapper" group. >>> To post to this group, send email to datamapper@googlegroups.com. >>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >>> For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
>> -- >> You received this message because you are subscribed to the Google Groups "DataMapper" group. >> To post to this group, send email to datamapper@googlegroups.com. >> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >> For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
describe "#count!" do subject { lambda { Loan.count!(money_flow) } } context "when a loan exists from giver to receiver" do let!(:loan) { Loan.gen } let(:money_flow) { MoneyFlow.gen(:giver => loan.loaner, :receiver => loan.loanee, :currency => loan.currency) } it { should_not change(Loan, :count) } end end
It tells me I got a Immutable Error. I feel strange on that. They have keys, and I didn't destroy the record. Can you see why? Thanks.
1) Loan#count! when a loan exists from giver to receiver Failure/Error: subject { lambda { Loan.count!(money_flow) } } DataMapper::ImmutableError: Immutable resource cannot be modified # ./lib/models.rb:49:in `count!' # ./spec/models_spec.rb:59:in `block (4 levels) in <top (required)>' # ./spec/models_spec.rb:63:in `block (4 levels) in <top (required)>'
> Objects are immutable when they've been deleted or frozen for some reason. Deleting a record from your data store will always result in that record being frozen.
> Is there a specific problem that you're having?
> -T
> On Mon, Jan 10, 2011 at 10:23 AM, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: > Dear All,
> Could anyone answer me when a resource should be immutable? And why? Thanks.
> Best regards, > Zhi-Qiang Lei > zhiqiang....@gmail.com
> -- > You received this message because you are subscribed to the Google Groups "DataMapper" group. > To post to this group, send email to datamapper@googlegroups.com. > To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
> -- > You received this message because you are subscribed to the Google Groups "DataMapper" group. > To post to this group, send email to datamapper@googlegroups.com. > To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
Best regards, Zhi-Qiang Lei zhiqiang....@gmail.com
You should probably just change that spec. The element that you want
to test is a proc (you hope) getting invoked inside of the subject
block, which is a weird pattern, and you don't need the #let blocks
really, since you only use those objects once.
Try:
describe "#count!" do
specify "when a loan exists from giver to receiver" do
loan = Loan.gen
money_flow = MoneyFlow.gen(:giver => loan.loaner, :receiver =>
loan.loanee, :currency => loan.currency)
expect do
Loan.count!(money_flow)
end.to_not change(Loan, :count)
end
end
I'm assuming you are using rspec 2, though it will work in rspec 1.x
with a syntax change. If you still get that error, post the new
backtrace here. At the very least the spec and the backtrace will be
more meaningful this way, and may be easier to debug (I hope).
On Jan 10, 10:42 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> When I test the "count!" class method as follow:
> describe "#count!" do
> subject { lambda { Loan.count!(money_flow) } }
> context "when a loan exists from giver to receiver" do
> let!(:loan) { Loan.gen }
> let(:money_flow) { MoneyFlow.gen(:giver => loan.loaner, :receiver => loan.loanee, :currency => loan.currency) }
> it { should_not change(Loan, :count) }
> end
> end
> It tells me I got a Immutable Error. I feel strange on that. They have keys, and I didn't destroy the record. Can you see why? Thanks.
> 1) Loan#count! when a loan exists from giver to receiver
> Failure/Error: subject { lambda { Loan.count!(money_flow) } }
> DataMapper::ImmutableError:
> Immutable resource cannot be modified
> # ./lib/models.rb:49:in `count!'
> # ./spec/models_spec.rb:59:in `block (4 levels) in <top (required)>'
> # ./spec/models_spec.rb:63:in `block (4 levels) in <top (required)>'
> On Jan 10, 2011, at 11:34 PM, Ted Han wrote:
> > Objects are immutable when they've been deleted or frozen for some reason. Deleting a record from your data store will always result in that record being frozen.
> > Is there a specific problem that you're having?
> > -T
> > On Mon, Jan 10, 2011 at 10:23 AM, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> > Dear All,
> > Could anyone answer me when a resource should be immutable? And why? Thanks.
> > Best regards,
> > Zhi-Qiang Lei
> > zhiqiang....@gmail.com
> > --
> > You received this message because you are subscribed to the Google Groups "DataMapper" group.
> > To post to this group, send email to datamapper@googlegroups.com.
> > To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
> > --
> > You received this message because you are subscribed to the Google Groups "DataMapper" group.
> > To post to this group, send email to datamapper@googlegroups.com.
> > To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
> Best regards,
> Zhi-Qiang Lei
> zhiqiang....@gmail.com
> You should probably just change that spec. The element that you want > to test is a proc (you hope) getting invoked inside of the subject > block, which is a weird pattern, and you don't need the #let blocks > really, since you only use those objects once.
> Try:
> describe "#count!" do > specify "when a loan exists from giver to receiver" do > loan = Loan.gen > money_flow = MoneyFlow.gen(:giver => loan.loaner, :receiver => > loan.loanee, :currency => loan.currency) > expect do > Loan.count!(money_flow) > end.to_not change(Loan, :count) > end > end
> I'm assuming you are using rspec 2, though it will work in rspec 1.x > with a syntax change. If you still get that error, post the new > backtrace here. At the very least the spec and the backtrace will be > more meaningful this way, and may be easier to debug (I hope).
> On Jan 10, 10:42 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >> Hi,
>> When I test the "count!" class method as follow:
>> describe "#count!" do >> subject { lambda { Loan.count!(money_flow) } } >> context "when a loan exists from giver to receiver" do >> let!(:loan) { Loan.gen } >> let(:money_flow) { MoneyFlow.gen(:giver => loan.loaner, :receiver => loan.loanee, :currency => loan.currency) } >> it { should_not change(Loan, :count) } >> end >> end
>> It tells me I got a Immutable Error. I feel strange on that. They have keys, and I didn't destroy the record. Can you see why? Thanks.
>> 1) Loan#count! when a loan exists from giver to receiver >> Failure/Error: subject { lambda { Loan.count!(money_flow) } } >> DataMapper::ImmutableError: >> Immutable resource cannot be modified >> # ./lib/models.rb:49:in `count!' >> # ./spec/models_spec.rb:59:in `block (4 levels) in <top (required)>' >> # ./spec/models_spec.rb:63:in `block (4 levels) in <top (required)>'
>> On Jan 10, 2011, at 11:34 PM, Ted Han wrote:
>>> Objects are immutable when they've been deleted or frozen for some reason. Deleting a record from your data store will always result in that record being frozen.
>>> Is there a specific problem that you're having?
>>> -T
>>> On Mon, Jan 10, 2011 at 10:23 AM, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >>> Dear All,
>>> Could anyone answer me when a resource should be immutable? And why? Thanks.
>>> Best regards, >>> Zhi-Qiang Lei >>> zhiqiang....@gmail.com
>>> -- >>> You received this message because you are subscribed to the Google Groups "DataMapper" group. >>> To post to this group, send email to datamapper@googlegroups.com. >>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
>>> -- >>> You received this message because you are subscribed to the Google Groups "DataMapper" group. >>> To post to this group, send email to datamapper@googlegroups.com. >>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
>> Best regards, >> Zhi-Qiang Lei >> zhiqiang....@gmail.com
> -- > You received this message because you are subscribed to the Google Groups "DataMapper" group. > To post to this group, send email to datamapper@googlegroups.com. > To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
Best regards, Zhi-Qiang Lei zhiqiang....@gmail.com
> On Jan 11, 2011, at 7:05 AM, RipTheJacker wrote:
> > You should probably just change that spec. The element that you want
> > to test is a proc (you hope) getting invoked inside of the subject
> > block, which is a weird pattern, and you don't need the #let blocks
> > really, since you only use those objects once.
> > Try:
> > describe "#count!" do
> > specify "when a loan exists from giver to receiver" do
> > loan = Loan.gen
> > money_flow = MoneyFlow.gen(:giver => loan.loaner, :receiver =>
> > loan.loanee, :currency => loan.currency)
> > expect do
> > Loan.count!(money_flow)
> > end.to_not change(Loan, :count)
> > end
> > end
> > I'm assuming you are using rspec 2, though it will work in rspec 1.x
> > with a syntax change. If you still get that error, post the new
> > backtrace here. At the very least the spec and the backtrace will be
> > more meaningful this way, and may be easier to debug (I hope).
> > On Jan 10, 10:42 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> >> Hi,
> >> When I test the "count!" class method as follow:
> >> describe "#count!" do
> >> subject { lambda { Loan.count!(money_flow) } }
> >> context "when a loan exists from giver to receiver" do
> >> let!(:loan) { Loan.gen }
> >> let(:money_flow) { MoneyFlow.gen(:giver => loan.loaner, :receiver => loan.loanee, :currency => loan.currency) }
> >> it { should_not change(Loan, :count) }
> >> end
> >> end
> >> It tells me I got a Immutable Error. I feel strange on that. They have keys, and I didn't destroy the record. Can you see why? Thanks.
> >> 1) Loan#count! when a loan exists from giver to receiver
> >> Failure/Error: subject { lambda { Loan.count!(money_flow) } }
> >> DataMapper::ImmutableError:
> >> Immutable resource cannot be modified
> >> # ./lib/models.rb:49:in `count!'
> >> # ./spec/models_spec.rb:59:in `block (4 levels) in <top (required)>'
> >> # ./spec/models_spec.rb:63:in `block (4 levels) in <top (required)>'
> >> On Jan 10, 2011, at 11:34 PM, Ted Han wrote:
> >>> Objects are immutable when they've been deleted or frozen for some reason. Deleting a record from your data store will always result in that record being frozen.
> >>> Is there a specific problem that you're having?
> >>> -T
> >>> On Mon, Jan 10, 2011 at 10:23 AM, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> >>> Dear All,
> >>> Could anyone answer me when a resource should be immutable? And why? Thanks.
> >>> Best regards,
> >>> Zhi-Qiang Lei
> >>> zhiqiang....@gmail.com
> >>> --
> >>> You received this message because you are subscribed to the Google Groups "DataMapper" group.
> >>> To post to this group, send email to datamapper@googlegroups.com.
> >>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com.
> >>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
> >>> --
> >>> You received this message because you are subscribed to the Google Groups "DataMapper" group.
> >>> To post to this group, send email to datamapper@googlegroups.com.
> >>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com.
> >>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
> >> Best regards,
> >> Zhi-Qiang Lei
> >> zhiqiang....@gmail.com
> > --
> > You received this message because you are subscribed to the Google Groups "DataMapper" group.
> > To post to this group, send email to datamapper@googlegroups.com.
> > To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
> Best regards,
> Zhi-Qiang Lei
> zhiqiang....@gmail.com
>> On Jan 11, 2011, at 7:05 AM, RipTheJacker wrote:
>>> You should probably just change that spec. The element that you want >>> to test is a proc (you hope) getting invoked inside of the subject >>> block, which is a weird pattern, and you don't need the #let blocks >>> really, since you only use those objects once.
>>> Try:
>>> describe "#count!" do >>> specify "when a loan exists from giver to receiver" do >>> loan = Loan.gen >>> money_flow = MoneyFlow.gen(:giver => loan.loaner, :receiver => >>> loan.loanee, :currency => loan.currency) >>> expect do >>> Loan.count!(money_flow) >>> end.to_not change(Loan, :count) >>> end >>> end
>>> I'm assuming you are using rspec 2, though it will work in rspec 1.x >>> with a syntax change. If you still get that error, post the new >>> backtrace here. At the very least the spec and the backtrace will be >>> more meaningful this way, and may be easier to debug (I hope).
>>> On Jan 10, 10:42 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >>>> Hi,
>>>> When I test the "count!" class method as follow:
>>>> describe "#count!" do >>>> subject { lambda { Loan.count!(money_flow) } } >>>> context "when a loan exists from giver to receiver" do >>>> let!(:loan) { Loan.gen } >>>> let(:money_flow) { MoneyFlow.gen(:giver => loan.loaner, :receiver => loan.loanee, :currency => loan.currency) } >>>> it { should_not change(Loan, :count) } >>>> end >>>> end
>>>> It tells me I got a Immutable Error. I feel strange on that. They have keys, and I didn't destroy the record. Can you see why? Thanks.
>>>> 1) Loan#count! when a loan exists from giver to receiver >>>> Failure/Error: subject { lambda { Loan.count!(money_flow) } } >>>> DataMapper::ImmutableError: >>>> Immutable resource cannot be modified >>>> # ./lib/models.rb:49:in `count!' >>>> # ./spec/models_spec.rb:59:in `block (4 levels) in <top (required)>' >>>> # ./spec/models_spec.rb:63:in `block (4 levels) in <top (required)>'
>>>> On Jan 10, 2011, at 11:34 PM, Ted Han wrote:
>>>>> Objects are immutable when they've been deleted or frozen for some reason. Deleting a record from your data store will always result in that record being frozen.
>>>>> Is there a specific problem that you're having?
>>>>> -T
>>>>> On Mon, Jan 10, 2011 at 10:23 AM, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >>>>> Dear All,
>>>>> Could anyone answer me when a resource should be immutable? And why? Thanks.
>>>>> Best regards, >>>>> Zhi-Qiang Lei >>>>> zhiqiang....@gmail.com
>>>>> -- >>>>> You received this message because you are subscribed to the Google Groups "DataMapper" group. >>>>> To post to this group, send email to datamapper@googlegroups.com. >>>>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >>>>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
>>>>> -- >>>>> You received this message because you are subscribed to the Google Groups "DataMapper" group. >>>>> To post to this group, send email to datamapper@googlegroups.com. >>>>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >>>>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
>>>> Best regards, >>>> Zhi-Qiang Lei >>>> zhiqiang....@gmail.com
>>> -- >>> You received this message because you are subscribed to the Google Groups "DataMapper" group. >>> To post to this group, send email to datamapper@googlegroups.com. >>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
>> Best regards, >> Zhi-Qiang Lei >> zhiqiang....@gmail.com
> -- > You received this message because you are subscribed to the Google Groups "DataMapper" group. > To post to this group, send email to datamapper@googlegroups.com. > To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
Best regards, Zhi-Qiang Lei zhiqiang....@gmail.com
Those won't make it immutable, but the key does need to be unique. So,
unless you can only have ONE Loan per Person you should probably
change those too. Rather than making them keys you probably mean to
have them as indexes, which I DataMapper does for you, and add an :id
Serial primary key to the model, the same as it is in your MoneyFlow
model.
On Jan 12, 12:28 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> >> On Jan 11, 2011, at 7:05 AM, RipTheJacker wrote:
> >>> You should probably just change that spec. The element that you want
> >>> to test is a proc (you hope) getting invoked inside of the subject
> >>> block, which is a weird pattern, and you don't need the #let blocks
> >>> really, since you only use those objects once.
> >>> Try:
> >>> describe "#count!" do
> >>> specify "when a loan exists from giver to receiver" do
> >>> loan = Loan.gen
> >>> money_flow = MoneyFlow.gen(:giver => loan.loaner, :receiver =>
> >>> loan.loanee, :currency => loan.currency)
> >>> expect do
> >>> Loan.count!(money_flow)
> >>> end.to_not change(Loan, :count)
> >>> end
> >>> end
> >>> I'm assuming you are using rspec 2, though it will work in rspec 1.x
> >>> with a syntax change. If you still get that error, post the new
> >>> backtrace here. At the very least the spec and the backtrace will be
> >>> more meaningful this way, and may be easier to debug (I hope).
> >>> On Jan 10, 10:42 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> >>>> Hi,
> >>>> When I test the "count!" class method as follow:
> >>>> describe "#count!" do
> >>>> subject { lambda { Loan.count!(money_flow) } }
> >>>> context "when a loan exists from giver to receiver" do
> >>>> let!(:loan) { Loan.gen }
> >>>> let(:money_flow) { MoneyFlow.gen(:giver => loan.loaner, :receiver => loan.loanee, :currency => loan.currency) }
> >>>> it { should_not change(Loan, :count) }
> >>>> end
> >>>> end
> >>>> It tells me I got a Immutable Error. I feel strange on that. They have keys, and I didn't destroy the record. Can you see why? Thanks.
> >>>> 1) Loan#count! when a loan exists from giver to receiver
> >>>> Failure/Error: subject { lambda { Loan.count!(money_flow) } }
> >>>> DataMapper::ImmutableError:
> >>>> Immutable resource cannot be modified
> >>>> # ./lib/models.rb:49:in `count!'
> >>>> # ./spec/models_spec.rb:59:in `block (4 levels) in <top (required)>'
> >>>> # ./spec/models_spec.rb:63:in `block (4 levels) in <top (required)>'
> >>>> On Jan 10, 2011, at 11:34 PM, Ted Han wrote:
> >>>>> Objects are immutable when they've been deleted or frozen for some reason. Deleting a record from your data store will always result in that record being frozen.
> >>>>> Is there a specific problem that you're having?
> >>>>> -T
> >>>>> On Mon, Jan 10, 2011 at 10:23 AM, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> >>>>> Dear All,
> >>>>> Could anyone answer me when a resource should be immutable? And why? Thanks.
> >>>>> Best regards,
> >>>>> Zhi-Qiang Lei
> >>>>> zhiqiang....@gmail.com
> >>>>> --
> >>>>> You received this message because you are subscribed to the Google Groups "DataMapper" group.
> >>>>> To post to this group, send email to datamapper@googlegroups.com.
> >>>>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com.
> >>>>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
> >>>>> --
> >>>>> You received this message because you are subscribed to the Google Groups "DataMapper" group.
> >>>>> To post to this group, send email to datamapper@googlegroups.com.
> >>>>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com.
> >>>>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
> >>>> Best regards,
> >>>> Zhi-Qiang Lei
> >>>> zhiqiang....@gmail.com
> Those won't make it immutable, but the key does need to be unique. So, > unless you can only have ONE Loan per Person you should probably > change those too. Rather than making them keys you probably mean to > have them as indexes, which I DataMapper does for you, and add an :id > Serial primary key to the model, the same as it is in your MoneyFlow > model.
> On Jan 12, 12:28 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >> Hi,
>> This model also has two more keys, they make a composite keys. This will also make it immutable?
>>>> On Jan 11, 2011, at 7:05 AM, RipTheJacker wrote:
>>>>> You should probably just change that spec. The element that you want >>>>> to test is a proc (you hope) getting invoked inside of the subject >>>>> block, which is a weird pattern, and you don't need the #let blocks >>>>> really, since you only use those objects once.
>>>>> Try:
>>>>> describe "#count!" do >>>>> specify "when a loan exists from giver to receiver" do >>>>> loan = Loan.gen >>>>> money_flow = MoneyFlow.gen(:giver => loan.loaner, :receiver => >>>>> loan.loanee, :currency => loan.currency) >>>>> expect do >>>>> Loan.count!(money_flow) >>>>> end.to_not change(Loan, :count) >>>>> end >>>>> end
>>>>> I'm assuming you are using rspec 2, though it will work in rspec 1.x >>>>> with a syntax change. If you still get that error, post the new >>>>> backtrace here. At the very least the spec and the backtrace will be >>>>> more meaningful this way, and may be easier to debug (I hope).
>>>>> On Jan 10, 10:42 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >>>>>> Hi,
>>>>>> When I test the "count!" class method as follow:
>>>>>> describe "#count!" do >>>>>> subject { lambda { Loan.count!(money_flow) } } >>>>>> context "when a loan exists from giver to receiver" do >>>>>> let!(:loan) { Loan.gen } >>>>>> let(:money_flow) { MoneyFlow.gen(:giver => loan.loaner, :receiver => loan.loanee, :currency => loan.currency) } >>>>>> it { should_not change(Loan, :count) } >>>>>> end >>>>>> end
>>>>>> It tells me I got a Immutable Error. I feel strange on that. They have keys, and I didn't destroy the record. Can you see why? Thanks.
>>>>>> 1) Loan#count! when a loan exists from giver to receiver >>>>>> Failure/Error: subject { lambda { Loan.count!(money_flow) } } >>>>>> DataMapper::ImmutableError: >>>>>> Immutable resource cannot be modified >>>>>> # ./lib/models.rb:49:in `count!' >>>>>> # ./spec/models_spec.rb:59:in `block (4 levels) in <top (required)>' >>>>>> # ./spec/models_spec.rb:63:in `block (4 levels) in <top (required)>'
>>>>>> On Jan 10, 2011, at 11:34 PM, Ted Han wrote:
>>>>>>> Objects are immutable when they've been deleted or frozen for some reason. Deleting a record from your data store will always result in that record being frozen.
>>>>>>> Is there a specific problem that you're having?
>>>>>>> -T
>>>>>>> On Mon, Jan 10, 2011 at 10:23 AM, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >>>>>>> Dear All,
>>>>>>> Could anyone answer me when a resource should be immutable? And why? Thanks.
>>>>>>> Best regards, >>>>>>> Zhi-Qiang Lei >>>>>>> zhiqiang....@gmail.com
>>>>>>> -- >>>>>>> You received this message because you are subscribed to the Google Groups "DataMapper" group. >>>>>>> To post to this group, send email to datamapper@googlegroups.com. >>>>>>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >>>>>>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
>>>>>>> -- >>>>>>> You received this message because you are subscribed to the Google Groups "DataMapper" group. >>>>>>> To post to this group, send email to datamapper@googlegroups.com. >>>>>>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >>>>>>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
>>>>>> Best regards, >>>>>> Zhi-Qiang Lei >>>>>> zhiqiang....@gmail.com
>>>>> -- >>>>> You received this message because you are subscribed to the Google Groups "DataMapper" group. >>>>> To post to this group, send email to datamapper@googlegroups.com. >>>>> To unsubscribe from this group,
Excuse me, a little more discussion please. In my past design, there should be ONLY ONE Loan record between two people in a specific currency. The composite keys match this requirement, don't they? But to make it immutable.
> Those won't make it immutable, but the key does need to be unique. So, > unless you can only have ONE Loan per Person you should probably > change those too. Rather than making them keys you probably mean to > have them as indexes, which I DataMapper does for you, and add an :id > Serial primary key to the model, the same as it is in your MoneyFlow > model.
> On Jan 12, 12:28 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >> Hi,
>> This model also has two more keys, they make a composite keys. This will also make it immutable?
>>>> On Jan 11, 2011, at 7:05 AM, RipTheJacker wrote:
>>>>> You should probably just change that spec. The element that you want >>>>> to test is a proc (you hope) getting invoked inside of the subject >>>>> block, which is a weird pattern, and you don't need the #let blocks >>>>> really, since you only use those objects once.
>>>>> Try:
>>>>> describe "#count!" do >>>>> specify "when a loan exists from giver to receiver" do >>>>> loan = Loan.gen >>>>> money_flow = MoneyFlow.gen(:giver => loan.loaner, :receiver => >>>>> loan.loanee, :currency => loan.currency) >>>>> expect do >>>>> Loan.count!(money_flow) >>>>> end.to_not change(Loan, :count) >>>>> end >>>>> end
>>>>> I'm assuming you are using rspec 2, though it will work in rspec 1.x >>>>> with a syntax change. If you still get that error, post the new >>>>> backtrace here. At the very least the spec and the backtrace will be >>>>> more meaningful this way, and may be easier to debug (I hope).
>>>>> On Jan 10, 10:42 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >>>>>> Hi,
>>>>>> When I test the "count!" class method as follow:
>>>>>> describe "#count!" do >>>>>> subject { lambda { Loan.count!(money_flow) } } >>>>>> context "when a loan exists from giver to receiver" do >>>>>> let!(:loan) { Loan.gen } >>>>>> let(:money_flow) { MoneyFlow.gen(:giver => loan.loaner, :receiver => loan.loanee, :currency => loan.currency) } >>>>>> it { should_not change(Loan, :count) } >>>>>> end >>>>>> end
>>>>>> It tells me I got a Immutable Error. I feel strange on that. They have keys, and I didn't destroy the record. Can you see why? Thanks.
>>>>>> 1) Loan#count! when a loan exists from giver to receiver >>>>>> Failure/Error: subject { lambda { Loan.count!(money_flow) } } >>>>>> DataMapper::ImmutableError: >>>>>> Immutable resource cannot be modified >>>>>> # ./lib/models.rb:49:in `count!' >>>>>> # ./spec/models_spec.rb:59:in `block (4 levels) in <top (required)>' >>>>>> # ./spec/models_spec.rb:63:in `block (4 levels) in <top (required)>'
>>>>>> On Jan 10, 2011, at 11:34 PM, Ted Han wrote:
>>>>>>> Objects are immutable when they've been deleted or frozen for some reason. Deleting a record from your data store will always result in that record being frozen.
>>>>>>> Is there a specific problem that you're having?
>>>>>>> -T
>>>>>>> On Mon, Jan 10, 2011 at 10:23 AM, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >>>>>>> Dear All,
>>>>>>> Could anyone answer me when a resource should be immutable? And why? Thanks.
>>>>>>> Best regards, >>>>>>> Zhi-Qiang Lei >>>>>>> zhiqiang....@gmail.com
>>>>>>> -- >>>>>>> You received this message because you are subscribed to the Google Groups "DataMapper" group. >>>>>>> To post to this group, send email to datamapper@googlegroups.com. >>>>>>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >>>>>>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
>>>>>>> -- >>>>>>> You received this message because you are subscribed to the Google Groups "DataMapper" group. >>>>>>> To post to this group, send email to datamapper@googlegroups.com. >>>>>>> To unsubscribe from this group, send email to datamapper+unsubscribe@googlegroups.com. >>>>>>> For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en.
>>>>>> Best regards, >>>>>> Zhi-Qiang Lei >>>>>> zhiqiang....@gmail.com
Yes, the composite keys match your requirement, so you can leave them
for the belongs_to associations. And I'm starting to think this may
really be a bug. See if this works:
remove the :key => true from :currency and add this:
validates_uniqueness_of :currency, :scope => [:loaner_id, :loanee_id]
On Jan 13, 1:53 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> Excuse me, a little more discussion please. In my past design, there should be ONLY ONE Loan record between two people in a specific currency. The composite keys match this requirement, don't they? But to make it immutable.
> On Jan 13, 2011, at 3:17 AM, RipTheJacker wrote:
> > Those won't make it immutable, but the key does need to be unique. So,
> > unless you can only have ONE Loan per Person you should probably
> > change those too. Rather than making them keys you probably mean to
> > have them as indexes, which I DataMapper does for you, and add an :id
> > Serial primary key to the model, the same as it is in your MoneyFlow
> > model.
> > On Jan 12, 12:28 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> >> Hi,
> >> This model also has two more keys, they make a composite keys. This will also make it immutable?
> >>>> On Jan 11, 2011, at 7:05 AM, RipTheJacker wrote:
> >>>>> You should probably just change that spec. The element that you want
> >>>>> to test is a proc (you hope) getting invoked inside of the subject
> >>>>> block, which is a weird pattern, and you don't need the #let blocks
> >>>>> really, since you only use those objects once.
> >>>>> Try:
> >>>>> describe "#count!" do
> >>>>> specify "when a loan exists from giver to receiver" do
> >>>>> loan = Loan.gen
> >>>>> money_flow = MoneyFlow.gen(:giver => loan.loaner, :receiver =>
> >>>>> loan.loanee, :currency => loan.currency)
> >>>>> expect do
> >>>>> Loan.count!(money_flow)
> >>>>> end.to_not change(Loan, :count)
> >>>>> end
> >>>>> end
> >>>>> I'm assuming you are using rspec 2, though it will work in rspec 1.x
> >>>>> with a syntax change. If you still get that error, post the new
> >>>>> backtrace here. At the very least the spec and the backtrace will be
> >>>>> more meaningful this way, and may be easier to debug (I hope).
> >>>>> On Jan 10, 10:42 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> >>>>>> Hi,
> >>>>>> When I test the "count!" class method as follow:
> >>>>>> describe "#count!" do
> >>>>>> subject { lambda { Loan.count!(money_flow) } }
> >>>>>> context "when a loan exists from giver to receiver" do
> >>>>>> let!(:loan) { Loan.gen }
> >>>>>> let(:money_flow) { MoneyFlow.gen(:giver => loan.loaner, :receiver => loan.loanee, :currency => loan.currency) }
> >>>>>> it { should_not change(Loan, :count) }
> >>>>>> end
> >>>>>> end
> >>>>>> It tells me I got a Immutable Error. I feel strange on that. They have keys, and I didn't destroy the record. Can you see why? Thanks.
> >>>>>> 1) Loan#count! when a loan exists from giver to receiver
> >>>>>> Failure/Error: subject { lambda { Loan.count!(money_flow) } }
> >>>>>> DataMapper::ImmutableError:
> >>>>>> Immutable resource cannot be modified
> >>>>>> # ./lib/models.rb:49:in `count!'
> >>>>>> # ./spec/models_spec.rb:59:in `block (4 levels) in <top (required)>'
> >>>>>> # ./spec/models_spec.rb:63:in `block (4 levels) in <top (required)>'
> >>>>>> On Jan 10, 2011, at 11:34 PM, Ted Han wrote:
> >>>>>>> Objects are immutable when they've been deleted or frozen for some reason. Deleting a record from your data store will always result in that record being frozen.
> >>>>>>> Is there a specific problem that you're having?
> >>>>>>> -T
> >>>>>>> On Mon, Jan 10, 2011 at 10:23 AM, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> >>>>>>> Dear All,
> >>>>>>> Could anyone answer me when a resource should be immutable? And why? Thanks.
Removing the key on currency only will lead to only one Loan record between two people, and they cannot have other Loan in different currency. So I remove all of them (keys), and add a id Serial property. With this validation, not ImmutableError recurs yet. Do you think I should submit a ticket for this?
> Yes, the composite keys match your requirement, so you can leave them > for the belongs_to associations. And I'm starting to think this may > really be a bug. See if this works:
> remove the :key => true from :currency and add this: > validates_uniqueness_of :currency, :scope => [:loaner_id, :loanee_id]
> On Jan 13, 1:53 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >> Excuse me, a little more discussion please. In my past design, there should be ONLY ONE Loan record between two people in a specific currency. The composite keys match this requirement, don't they? But to make it immutable.
>> On Jan 13, 2011, at 3:17 AM, RipTheJacker wrote:
>>> Those won't make it immutable, but the key does need to be unique. So, >>> unless you can only have ONE Loan per Person you should probably >>> change those too. Rather than making them keys you probably mean to >>> have them as indexes, which I DataMapper does for you, and add an :id >>> Serial primary key to the model, the same as it is in your MoneyFlow >>> model.
>>> On Jan 12, 12:28 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >>>> Hi,
>>>> This model also has two more keys, they make a composite keys. This will also make it immutable?
>>>>>> On Jan 11, 2011, at 7:05 AM, RipTheJacker wrote:
>>>>>>> You should probably just change that spec. The element that you want >>>>>>> to test is a proc (you hope) getting invoked inside of the subject >>>>>>> block, which is a weird pattern, and you don't need the #let blocks >>>>>>> really, since you only use those objects once.
>>>>>>> Try:
>>>>>>> describe "#count!" do >>>>>>> specify "when a loan exists from giver to receiver" do >>>>>>> loan = Loan.gen >>>>>>> money_flow = MoneyFlow.gen(:giver => loan.loaner, :receiver => >>>>>>> loan.loanee, :currency => loan.currency) >>>>>>> expect do >>>>>>> Loan.count!(money_flow) >>>>>>> end.to_not change(Loan, :count) >>>>>>> end >>>>>>> end
>>>>>>> I'm assuming you are using rspec 2, though it will work in rspec 1.x >>>>>>> with a syntax change. If you still get that error, post the new >>>>>>> backtrace here. At the very least the spec and the backtrace will be >>>>>>> more meaningful this way, and may be easier to debug (I hope).
>>>>>>> On Jan 10, 10:42 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >>>>>>>> Hi,
>>>>>>>> When I test the "count!" class method as follow:
>>>>>>>> describe "#count!" do >>>>>>>> subject { lambda { Loan.count!(money_flow) } } >>>>>>>> context "when a loan exists from giver to receiver" do >>>>>>>> let!(:loan) { Loan.gen } >>>>>>>> let(:money_flow) { MoneyFlow.gen(:giver => loan.loaner, :receiver => loan.loanee, :currency => loan.currency) } >>>>>>>> it { should_not change(Loan, :count) } >>>>>>>> end >>>>>>>> end
>>>>>>>> It tells me I got a Immutable Error. I feel strange on that. They have keys, and I didn't destroy the record. Can you see why? Thanks.
>>>>>>>> 1) Loan#count! when a loan exists from giver to receiver >>>>>>>> Failure/Error: subject { lambda { Loan.count!(money_flow) } } >>>>>>>> DataMapper::ImmutableError: >>>>>>>> Immutable resource cannot be modified >>>>>>>> # ./lib/models.rb:49:in `count!' >>>>>>>> # ./spec/models_spec.rb:59:in `block (4 levels) in <top (required)>' >>>>>>>> # ./spec/models_spec.rb:63:in `block (4 levels) in <top (required)>'
>>>>>>>> On Jan 10, 2011, at 11:34 PM, Ted Han wrote:
>>>>>>>>> Objects are immutable when they've been deleted or frozen for some reason. Deleting a record from your data store will always result in that record being frozen.
>>>>>>>>> Is there a specific problem that you're having?
>>>>>>>>> -T
>>>>>>>>> On Mon, Jan 10, 2011 at 10:23 AM, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote: >>>>>>>>> Dear All,
> Removing the key on currency only will lead to only one Loan record between two people, and they cannot have other Loan in different currency. So I remove all of them (keys), and add a id Serial property. With this validation, not ImmutableError recurs yet.
> Do you think I should submit a ticket for this?
> On Jan 14, 2011, at 7:39 AM, RipTheJacker wrote:
> > Yes, the composite keys match your requirement, so you can leave them
> > for the belongs_to associations. And I'm starting to think this may
> > really be a bug. See if this works:
> > remove the :key => true from :currency and add this:
> > validates_uniqueness_of :currency, :scope => [:loaner_id, :loanee_id]
> > On Jan 13, 1:53 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> >> Excuse me, a little more discussion please. In my past design, there should be ONLY ONE Loan record between two people in a specific currency. The composite keys match this requirement, don't they? But to make it immutable.
> >> On Jan 13, 2011, at 3:17 AM, RipTheJacker wrote:
> >>> Those won't make it immutable, but the key does need to be unique. So,
> >>> unless you can only have ONE Loan per Person you should probably
> >>> change those too. Rather than making them keys you probably mean to
> >>> have them as indexes, which I DataMapper does for you, and add an :id
> >>> Serial primary key to the model, the same as it is in your MoneyFlow
> >>> model.
> >>> On Jan 12, 12:28 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> >>>> Hi,
> >>>> This model also has two more keys, they make a composite keys. This will also make it immutable?
> >>>>>> On Jan 11, 2011, at 7:05 AM, RipTheJacker wrote:
> >>>>>>> You should probably just change that spec. The element that you want
> >>>>>>> to test is a proc (you hope) getting invoked inside of the subject
> >>>>>>> block, which is a weird pattern, and you don't need the #let blocks
> >>>>>>> really, since you only use those objects once.
> >>>>>>> Try:
> >>>>>>> describe "#count!" do
> >>>>>>> specify "when a loan exists from giver to receiver" do
> >>>>>>> loan = Loan.gen
> >>>>>>> money_flow = MoneyFlow.gen(:giver => loan.loaner, :receiver =>
> >>>>>>> loan.loanee, :currency => loan.currency)
> >>>>>>> expect do
> >>>>>>> Loan.count!(money_flow)
> >>>>>>> end.to_not change(Loan, :count)
> >>>>>>> end
> >>>>>>> end
> >>>>>>> I'm assuming you are using rspec 2, though it will work in rspec 1.x
> >>>>>>> with a syntax change. If you still get that error, post the new
> >>>>>>> backtrace here. At the very least the spec and the backtrace will be
> >>>>>>> more meaningful this way, and may be easier to debug (I hope).
> >>>>>>> On Jan 10, 10:42 am, Zhi-Qiang Lei <zhiqiang....@gmail.com> wrote:
> >>>>>>>> Hi,