From 1faf24bfa5ea1b4a5032b4dd748c5d60764f45cd Mon Sep 17 00:00:00 2001 From: Michael Harrison Date: Fri, 25 Jun 2010 10:47:35 -0400 Subject: [PATCH] Adds tests for 'new' and 'edit' files --- .../mustache/scaffold_generator_test.rb | 169 ++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/test/lib/generators/mustache/scaffold_generator_test.rb b/test/lib/generators/mustache/scaffold_generator_test.rb index b516f92..fdb7961 100644 --- a/test/lib/generators/mustache/scaffold_generator_test.rb +++ b/test/lib/generators/mustache/scaffold_generator_test.rb @@ -18,6 +18,24 @@ class Mustache::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase %w(index edit new show).each { |view| assert_file "app/templates/product_lines/#{view}.html.mustache" } end + ### SHOW + + test "should place methods for each attribute in the show view" do + run_generator + assert_file "app/views/product_lines/show.rb", + %r(def title) + assert_file "app/views/product_lines/show.rb", + %r(def price) + end + + test "should place methods for edit path and index path in the show view" do + run_generator + assert_file "app/views/product_lines/show.rb", + %r(def edit_path) + assert_file "app/views/product_lines/show.rb", + %r(def index_path) + end + test "should place attribute tags in the mustache template for show action" do run_generator assert_file "app/templates/product_lines/show.html.mustache", @@ -26,6 +44,28 @@ class Mustache::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase %r({{price}}) end + test "should place tags for edit path and index path in the mustache template for show action" do + run_generator + assert_file "app/templates/product_lines/show.html.mustache", + %r({{edit_path}}) + assert_file "app/templates/product_lines/show.html.mustache", + %r({{index_path}}) + end + + ### INDEX + + test "should place methods for listing each item in the index view" do + run_generator + assert_file "app/views/product_lines/index.rb", + %r(def listing) + end + + test "should place methods for new path in the index view" do + run_generator + assert_file "app/views/product_lines/index.rb", + %r(def new_path) + end + test "should place 'listing' loop tags in the mustache template for index action" do run_generator assert_file "app/templates/product_lines/index.html.mustache", @@ -34,5 +74,134 @@ class Mustache::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase %r({{/listing}}) end + test "should place a tag for each attribute in the mustache template for index action" do + run_generator + assert_file "app/templates/product_lines/index.html.mustache", + %r({{title}}) + assert_file "app/templates/product_lines/index.html.mustache", + %r({{price}}) + end + + test "should place a tag for the item's show link the mustache template for index action" do + run_generator + assert_file "app/templates/product_lines/index.html.mustache", + %r({{show_path}}) + end + + test "should place a tag for a new index link the mustache template for index action" do + run_generator + assert_file "app/templates/product_lines/index.html.mustache", + %r({{new_path}}) + end + + + + ### NEW + + test "should place a method that returns a form tag to create item" do + run_generator + assert_file "app/views/product_lines/new.rb", + %r(new_form_tag\s*form_tag\(create_path,) + end + + test "should place label and form input methods for each item attribute in the new view" do + run_generator + assert_file "app/views/product_lines/new.rb", + %r(def title_label) + assert_file "app/views/product_lines/new.rb", + %r(def title_text_field) + assert_file "app/views/product_lines/new.rb", + %r(def price_label) + assert_file "app/views/product_lines/new.rb", + %r(def price_text_field) + end + + test "should place methods for create path and index path in the new view" do + run_generator + assert_file "app/views/product_lines/new.rb", + %r(def index_path) + assert_file "app/views/product_lines/new.rb", + %r(def create_path) + end + + + test "should place a new form tag in the mustache template for new action" do + run_generator + assert_file "app/templates/product_lines/new.html.mustache", + %r({{new_form_tag}}) + end + + test "should place attribute tags in the mustache template for new action" do + run_generator + assert_file "app/templates/product_lines/new.html.mustache", + %r({{title_label}}) + assert_file "app/templates/product_lines/new.html.mustache", + %r({{title_text_field}}) + assert_file "app/templates/product_lines/new.html.mustache", + %r({{price_text_field}}) + assert_file "app/templates/product_lines/new.html.mustache", + %r({{price_label}}) + end + + test "should place tags for index path in the mustache template for new action" do + run_generator + assert_file "app/templates/product_lines/new.html.mustache", + %r({{index_path}}) + end + + + ### EDIT + + test "should place a method that returns a form tag to update item in the edit view" do + run_generator + assert_file "app/views/product_lines/edit.rb", + %r(edit_form_tag\s*form_tag\(update_path,) + end + + test "should place label and form input methods for each item attribute in the edit view" do + run_generator + assert_file "app/views/product_lines/edit.rb", + %r(def title_label) + assert_file "app/views/product_lines/edit.rb", + %r(def title_text_field) + assert_file "app/views/product_lines/edit.rb", + %r(def price_label) + assert_file "app/views/product_lines/edit.rb", + %r(def price_text_field) + end + + test "should place methods for update path and show path in the edit view" do + run_generator + assert_file "app/views/product_lines/edit.rb", + %r(def show_path) + assert_file "app/views/product_lines/edit.rb", + %r(def update_path) + end + + + test "should place an edit form tag in the mustache template for edit action" do + run_generator + assert_file "app/templates/product_lines/edit.html.mustache", + %r({{edit_form_tag}}) + end + + test "should place attribute tags in the mustache template for edit action" do + run_generator + assert_file "app/templates/product_lines/edit.html.mustache", + %r({{title_label}}) + assert_file "app/templates/product_lines/edit.html.mustache", + %r({{title_text_field}}) + assert_file "app/templates/product_lines/edit.html.mustache", + %r({{price_text_field}}) + assert_file "app/templates/product_lines/edit.html.mustache", + %r({{price_label}}) + end + + test "should place tags for show path in the mustache template for edit action" do + run_generator + assert_file "app/templates/product_lines/edit.html.mustache", + %r({{show_path}}) + end + end