Permalink
Browse files

Added example and spec

  • Loading branch information...
1 parent b7bdebd commit 66be14ce4719f3da63ad80744054146b13681210 @megle megle committed Feb 27, 2012
Showing with 39 additions and 0 deletions.
  1. +17 −0 examples/search_query.rb
  2. +22 −0 spec/examples/search_query_spec.rb
View
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+require_relative './../spec/spec_helper'
+
+class SearchQuery
+ include ROXML
+ xml_accessor :query
+ xml_accessor :max_results, :else => 20, :as => Integer
+ xml_accessor :language, :else => 'EN'
+end
+
+
+unless defined?(RSpec)
+ q = SearchQuery.new
+ q.query = "Some random query string."
+ puts q.to_xml.to_s
+end
+
@@ -0,0 +1,22 @@
+require 'spec_helper'
+require_relative './../../examples/search_query'
+
+describe SearchQuery do
+
+ before do
+ @search = SearchQuery.new
+ @search.query = 'This is a random search query.'
+
+ @saved_search = SearchQuery.from_xml("<searchquery><query>Search for something</query></searchquery>")
+ end
+
+ it 'should return the default value for all attributes where no value is set' do
+ @search.language.should == 'EN'
+ @search.max_results == 20
+ end
+
+ it 'should respect the defaults when loading from xml' do
+ @saved_search.language.should == 'EN'
+ @saved_search.max_results == 20
+ end
+end

0 comments on commit 66be14c

Please sign in to comment.