Skip to content

Commit

Permalink
Tests for CamelCaseModels.
Browse files Browse the repository at this point in the history
  • Loading branch information
clayallsopp committed May 20, 2012
1 parent 3de27b4 commit da4737b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ def user_id
end
end

class CamelCaseModel < RemoteModule::RemoteModel
has_one :another_camel_case_model
has_many :bunch_of_camel_case_models
end

class AnotherCamelCaseModel < RemoteModule::RemoteModel
attr_accessor :id

belongs_to :camel_case_model
end

class BunchOfCamelCaseModel < RemoteModule::RemoteModel
belongs_to :camel_case_model
end

describe "The active record-esque stuff" do
it "creates object from hash" do
hash = {id: 5, question: "Hello my name is clay"}
Expand Down Expand Up @@ -76,4 +91,23 @@ def check_question_and_answers(q, answers)
end
}
end

it "works with camel cased models" do
c = CamelCaseModel.new({another_camel_case_model: {id: 7}, bunch_of_camel_case_models: [{}, {}]})
c.another_camel_case_model.class.should == AnotherCamelCaseModel
c.another_camel_case_model.id.should == 7
c.bunch_of_camel_case_models.count.should == 2
c.bunch_of_camel_case_models.each {|model|
model.class.should == BunchOfCamelCaseModel
}

c.setAnotherCamelCaseModel({id: 8})
c.another_camel_case_model.id.should == 8

c.setBunchOfCamelCaseModels([{}, {}, {}])
c.bunch_of_camel_case_models.count.should == 3
c.bunch_of_camel_case_models.each {|model|
model.class.should == BunchOfCamelCaseModel
}
end
end

0 comments on commit da4737b

Please sign in to comment.