= sample for ruby on rails

This directory contains amrita2-rails briged and two set of modified
version of 'Todo List Tutorial' of Ruby on Rails. The original version
is here.

  * http://manuals.rubyonrails.com/read/book/7

Directory todoapp1 contains simple version which uses only basic API
of Amrita2. This is direct translation of the original tutorial which
uses ERb template.

Directory todoapp2 contains a version which uses Active PO API and
parts template of Amrita2. This is more complex but is better for
maintainance.

These was made from the work of Jamis Buck.

  * http://one.textdrive.com/pipermail/rails/2005-February/003169.html
  * http://ruby.jamisbuck.org/amrita-view.zip

These samples are tested under Rails-0.9.5 .

== Steps to applying and using this patch:

  1) Apply action_view-base.diff patch to the actionpack directory
     (This patch is same as Jamis's work)

  2) Create Database and the project as the original tutorial.

     * http://manuals.rubyonrails.com/read/chapter/36
     * http://manuals.rubyonrails.com/read/chapter/37

  3) Make symbolic links from Todo base directory

     ln -s (amrita2 path)/sample/rails/amrita2_view.rb (Todo Path)/lib
     rm -r (Todo Path)/app
     ln -s (amrita2 path)/sample/rails/todoapp1 (Todo Path)/app

  4) Add the following two lines to your config/environment.rb file:

      require 'amrita2_view'
      ActionView::Base.register_template_handler "a2html", Amrita2View::Base
        
  5) run Rails

  6) see http://localhost:3000/todo/list

You can link todoapp2 instead of todoapp1 at 3rd step if you like.

== Changed Sources

There are no changes at controllers and model execpt

  attr_reader :done, :not_done

in controllers/todo_controller.rb.

The HTML template (views/todo/list.a2html) was changed as a plain HTML
file. And the presentation logic for it is in helpers (helpers/todo_helper.rb)

== Testing with Amrita2 Mock Template

amrita2_mock_view.rb supports testing with Amrita2 mock template.

1)  link it

  ln -s (amrita2 path)/sample/rails/amrita2_mock_view.rb (Todo Path)/lib

2) Add the following two lines to your config/environment.rb file:


  unless ENV['AMRITA2_MOCK']
    require 'amrita2_view'
    ActionView::Base.register_template_handler "a2html", Amrita2View::Base
  else
    require 'amrita2_mock_view'
    ActionView::Base.register_template_handler "a2html", Amrita2MockView::Base
  end


3) setup fixture(~/Todo/test/fixtures/todos.yml)

  notdone1:
    id: 1
    done: 0
    description: not done 1

  notdone2:
    id: 2
    done: 0
    description: not done 2

  done1:
    id: 3
    done: 1
    description: done 1

  done2:
    id: 4
    done: 1
    description: done 2

4) run todo_controller_test.rb

  $ AMRITA2_MOCK=1 ruby test/functional/todo_controller_test.rb  

This test checks the values your VIEW set like this

  def test_list
    get :list
    assert_success
    if ENV['AMRITA2_MOCK']
      r = $AMRITA2_MOCK_RESULT
      assert_equal('not done 1', r[:not_done][0][:description])
      assert_equal('Edit', r[:not_done][0][:edit_link])
      assert_equal('/todo/edit/1', r[:not_done][0][:edit_link_attr][:href])
    end
  end

