spec/model_specs/person_spec.rb in jtable-rails-0.1.2 vs spec/model_specs/person_spec.rb in jtable-rails-0.1.3

- old
+ new

@@ -26,13 +26,20 @@ Person.respond_to?(:jtable_default).should be_true Person.respond_to?(:jtable_query).should be_true [:first_name, :last_name, :age, :date_of_birth, :gender, :alive].each do |attribute| Person.respond_to?("jtable_search_#{attribute}").should be_true Person.respond_to?("jtable_order_#{attribute}").should be_true + Person.respond_to?("jtable_attributes").should be_true + Person.new.respond_to?("jtable_attribute_#{attribute}").should be_true + Person.new.respond_to?("jtable_item").should be_true end end + it "should know jtables attributes" do + Person.jtable_attributes.should eql([:first_name, :last_name, :age, :date_of_birth, :gender, :alive]) + end + it "should load initial set" do Person.jtable_query(@params).to_json.should eql(Person.all.to_json) end it "should paginate" do @@ -67,7 +74,12 @@ it "should order" do @params[:sort_column] = "age" @params[:sort_direction] = "ASC" Person.jtable_query(@params).to_json.should eql(Person.order('age ASC').to_json) + end + + it "should format an item for jtable" do + person = Fabricate(:person, :first_name => "John", :last_name => "Smith", :age => 21, :date_of_birth => 21.years.ago, :gender => "Male", :alive => true) + person.jtable_item.should eql({:id => person.id, :first_name => "John", :last_name => "Smith", :age => 21, :date_of_birth => 21.years.ago.strftime("%m/%d/%Y %I:%M%P"), :gender => "Male", :alive => true}) end end \ No newline at end of file