trestle_generator 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +1 -1
  2. data/templates/functional_test.rb +26 -0
  3. metadata +3 -3
data/README CHANGED
@@ -46,7 +46,7 @@ solve the problem of GET vs POST more cleanly and comprehensively.
46
46
  Why switch from scaffolds to trestles? USABILITY
47
47
  --------------------------------------------------------------------------------
48
48
 
49
- Trestle controllers have just four actions (index, new, edit, and destroy).
49
+ Trestle controllers have just five actions (list, new, show, edit, and destroy).
50
50
  Contrast this with scaffold controllers which have eight actions to implement
51
51
  the same functionality. This is mostly a matter of taste, but Rails developers
52
52
  appreciate more than most that �less is more.�
@@ -41,6 +41,17 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
41
41
  assert_raise(ActiveRecord::RecordNotFound) { <%= model_name %>.find(1) }
42
42
  end
43
43
 
44
+ def test_destroy<%= suffix %>_without_id
45
+ assert_not_nil <%= model_name %>.find(1)
46
+
47
+ post 'destroy<%= suffix %>'
48
+ assert_response :redirect
49
+ assert_redirected_to :action => 'list<%= suffix %>'
50
+ assert flash.has_key?(:notice)
51
+
52
+ assert_not_nil <%= model_name %>.find(1)
53
+ end
54
+
44
55
  def test_edit<%= suffix %>_using_get
45
56
  get 'edit<%= suffix %>', :id => 1
46
57
 
@@ -57,6 +68,13 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
57
68
  assert_redirected_to :action => 'show<%= suffix %>', :id => 1
58
69
  end
59
70
 
71
+ def test_edit<%= suffix %>_without_id
72
+ post 'edit<%= suffix %>'
73
+ assert_response :redirect
74
+ assert_redirected_to :action => 'list<%= suffix %>'
75
+ assert flash.has_key?(:notice)
76
+ end
77
+
60
78
  def test_list<%= suffix %>
61
79
  get 'list<%= suffix %>'
62
80
 
@@ -95,4 +113,12 @@ class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
95
113
  assert_not_nil assigns(:<%= singular_name %>)
96
114
  assert assigns(:<%= singular_name %>).valid?
97
115
  end
116
+
117
+ def test_show<%= suffix %>_without_id
118
+ get 'show<%= suffix %>'
119
+
120
+ assert_response :redirect
121
+ assert_redirected_to :action => 'list<%= suffix %>'
122
+ assert flash.has_key?(:notice)
123
+ end
98
124
  end
metadata CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: trestle_generator
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.4
7
- date: 2006-05-11 00:00:00 -05:00
6
+ version: 1.1.5
7
+ date: 2006-05-18 00:00:00 -05:00
8
8
  summary: "[Rails] A drop-in replacement for the scaffold generator that produces production-ready controllers that are safe from state-changing HTTP GET requests and that have streamlined URLs."
9
9
  require_paths:
10
10
  - templates
11
11
  email: nils@alumni.rice.edu
12
12
  homepage: http://trestle.rubyforge.org/
13
13
  rubyforge_project: trestle
14
- description: "============================================================================ Trestle Generator ============================================================================ A drop-in replacement for Ruby on Rails\x92s scaffold generator Everybody loves scaffolding, and with good reason. It\x92s the feature of the Ruby on Rails framework that makes a database table editable on the web in mere seconds, and with just a few lines of generated Ruby code. The trestle generator is drop-in replacement for the Rails scaffold generator. It produces scaffolding that\x92s more like production-quality code while maintaining all the rapid goodness you know and love about Rails. Don\x92t drive your train across a gorge with nothing but a scaffold underneath it. Use a trestle instead! Trestles have two advantages over scaffolds: * More elegant handling of HTTP POST and GET requests * A streamlined URL structure that makes your application easier to use Downloading and installation is a breeze with RubyGems, the package manager that\x92s included in most Ruby distributions. Just type the following at a command line: gem install trestle_generator Generating trestles for your database tables is also a one-step process: script/generate trestle YourModelNameHere ---------------------------------------------------------------------------- Why switch from scaffolds to trestles? SAFETY ---------------------------------------------------------------------------- The trestle generator produces Rails views that use HTTP POST to request changes (instead of GET). It also generates Rails controllers that execute such changes only for HTTP POST requests. Well-behaved web applications must protect user data against unwanted changes, including those arising from errant HTTP GET requests such as Google Web Accelerator is known to make. The scaffolding provided by Rails v1.1 is better about this than Rails v1.0 was, but trestles solve the problem of GET vs POST more cleanly and comprehensively. ---------------------------------------------------------------------------- Why switch from scaffolds to trestles? USABILITY ---------------------------------------------------------------------------- Trestle controllers have just four actions (index, new, edit, and destroy). Contrast this with scaffold controllers which have eight actions to implement the same functionality. This is mostly a matter of taste, but Rails developers appreciate more than most that \x93less is more.\x94 Just as important as aesthetics is the fact that trestle controllers better reflect GET and POST semantics, making for more intelligible HTTP conversations in your applications. (Apparently, Tobias L\xFCtke wrote a postback_generator RubyGem with a similar philosophy, but trestles take the concept further.) Use trestles instead of scaffolding and you will find yourself throwing away and tweaking less code as you build out applications. As joyous as Ruby programming is, less code is still a good thing. Let\x92s look at some of the differences between trestles and scaffolds. A scaffold for a database table named \x91people\x92 has the following HTTP interface: URL Result ============================================================================ /people Lists existing person records /people/list ---------------------------------------------------------------------------- /people/new Shows an empty person form ---------------------------------------------------------------------------- /people/create Creates a new person record from request parameters ---------------------------------------------------------------------------- /people/show/99 Shows the person record having ID 99 ---------------------------------------------------------------------------- /people/edit/99 Shows a person form for the person record having ID 99 ---------------------------------------------------------------------------- /people/update/99 Updates the person record having ID 99 using request parameters ---------------------------------------------------------------------------- /people/destroy/99 Deletes the person record having ID 99 As of Rails v1.1, scaffold controllers reject requests to insert, update and delete records if the request is HTTP GET instead of POST. This is a safety improvement, but the design still leaves something to be desired. Contrast this with the HTTP interface of the equivalent trestle controller: URL HTTP Method Result ============================================================================ /people GET or POST Lists existing person records ---------------------------------------------------------------------------- /people/new GET Shows an empty person form POST Creates a new person record from request parameters ---------------------------------------------------------------------------- /people/99 GET or POST Shows the person record having ID 99 ---------------------------------------------------------------------------- /people/99/edit GET Shows a person form for the person record having ID 99 POST Updates the person record having ID 99 using request parameters ---------------------------------------------------------------------------- /people/99/destroy GET Redirects to /people/99/edit with a notice that the user must click the form\x92s Destroy button in order to destroy a record POST Deletes the person record having ID 99 after prompting the user for confirmation A trestle degrades gracefully if the user has JavaScript turned off. And the hierarchical nature of trestle URLs, wherein the ID comes before the verb, lets the user click the Up One Level button on the Google Toolbar to explore the application. (The Up One Level button clips one element off the end of the current URL.) Scaffold URLs do not play nicely with the Up One Level button. The trestle interface is not just pain relief for users without JavaScript and those who like the Up One Level button. If you type URLs by hand, you get a friendly notice\x97\x97instead of a Rails exception\x97\x97if a request is missing an ID. There is simply less opportunity for error. That\x92s a tried-and-true way to up the usability factor. Do yourself and your users a favor by switching from scaffolds to trestles. Visit the RubyForge page (http://trestle.rubyforge.org/) for this open-source project. Contact me at nils@alumni.rice.edu. -- //. _/. Nils Jonsson"
14
+ description: "Industrial-strength scaffolding for Ruby on Rails application development. Don\x92t drive your train across a gorge with nothing but a scaffold underneath it. Use a trestle instead! Learn more at http://trestle.rubyforge.org/."
15
15
  autorequire:
16
16
  default_executable:
17
17
  bindir: bin