October 18, 2009

WIX Free Flash template design

I have seen many free template websites but those are only for the normal webpage generated as HTML. This morning I've played around with WIX which allows me to create my flash website with many pretty templates. It's easy to customize and change everything.

You can do it by yourself with www.wix.com

Here is mine: www.wix.com/samneang/samneang

flash fly characters should be checked for it's flash animation.

October 08, 2009

Testing ActiveResource

I was suffered at the begining of this testing but later I've found some sample ways to solve it.

//Testing with mocking object's method
//Sample structure of HttpMock: mock.http_method(path, request_headers = {}, body = nil, status = 200, response_headers = {})

def setup
@matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
ActiveResource::HttpMock.respond_to do |mock|
mock.post "/people.xml", {}, @matz, 201, "Location" => "/people/1.xml"
mock.get "/people/1.xml", {}, @matz
mock.put "/people/1.xml", {}, nil, 204
mock.delete "/people/1.xml", {}, nil, 200
end
end

def test_get_matz
person = Person.find(1)
assert_equal "Matz", person.name
end
------------------------------------

def setup
@matz = { :id => 1, :name => "Matz" }.to_xml(:root => "person")
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people/1.xml", {}, @matz
end
end

def test_should_request_remote_service
person = Person.find(1) # Call the remote service

# This request object has the same HTTP method and path as declared by the mock
expected_request = ActiveResource::Request.new(:get, "/people/1.xml")

# Assert that the mock received, and responded to, the expected request from the model
assert ActiveResource::HttpMock.requests.include?(expected_request)
end
------------------------------------

def test_delete
assert Person.delete(1)
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people/1.xml", {}, nil, 404
end
assert_raises(ActiveResource::ResourceNotFound) { Person.find(1) }
end
------------------------------------

@matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person')
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people/1.xml", {}, @matz
end

//Testing by deleting the record and return RecordNotFound(404)
def test_delete
assert Person.delete(1)
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/people/1.xml", {}, nil, 404
end
assert_raises(ActiveResource::ResourceNotFound) { Person.find(1) }
end

October 07, 2009

HTTParty, Awesome_nested_set, rdoc option(s)

For those who wanna use HTTParty well with RoR, you can follow this link: HTTParty.

Talking about listing data as Tree and easy to search, I would like to present you about awesome_nested_set which is cool.

It was not bad that some guys don't know how to generate their Rdoc as the whole structure after they generate it first time because they don't delete the doc folder when they wanna generate it as the whole again.
To generate your RDoc without some specific folders or files you need to type as bellow:

rdoc --exclude folder1 --exclude folder2 --exclude folder3

October 05, 2009

RESTful Pagination with Ruby on Rails

Currently I'm working on RoR project and I've seen one plug-in call Will-paginate but it works well with ActiveRecord. There's one blog posts that it also work with ActiveResource but I'm not quiet clear about it. here is the link: Will-paginate

But I've seen another web in stackoverflow which also talk about the way to do pagination with REST. I think, I'll try with Stackoverflow first and combine with will-paginate by using ActiveRecord, otherwise I will use Will-paginate with both ActiveRecord and ActiveResource.