diff --git a/tracks/app/controllers/project_controller.rb b/tracks/app/controllers/project_controller.rb index f98f0f29..c554cd4c 100644 --- a/tracks/app/controllers/project_controller.rb +++ b/tracks/app/controllers/project_controller.rb @@ -58,16 +58,10 @@ class ProjectController < ApplicationController end def new_project - project = @user.projects.build - project.attributes = params['project'] - project.name = deurlize(project.name) - - if project.save - render :partial => 'project_listing', :locals => { :project_listing => project } - else - flash["warning"] = "Couldn't update new project" - render :text => "" - end + @project = @user.projects.build + @project.attributes = params['project'] + @project.name = deurlize(@project.name) + @saved = @project.save end # Called by a form button diff --git a/tracks/app/helpers/project_helper.rb b/tracks/app/helpers/project_helper.rb index 12c6d3c7..336f7a32 100644 --- a/tracks/app/helpers/project_helper.rb +++ b/tracks/app/helpers/project_helper.rb @@ -1,2 +1,12 @@ module ProjectHelper + +def get_listing_sortable_options + { + :tag => 'div', + :handle => 'handle', + :complete => visual_effect(:highlight, 'list-projects'), + :url => {:controller => 'project', :action => 'order'} + } +end + end diff --git a/tracks/app/models/project.rb b/tracks/app/models/project.rb index 2cbaa720..f6c78210 100644 --- a/tracks/app/models/project.rb +++ b/tracks/app/models/project.rb @@ -12,7 +12,8 @@ class Project < ActiveRecord::Base validates_presence_of :name, :message => "project must have a name" validates_length_of :name, :maximum => 255, :message => "project name must be less than 256 characters" validates_uniqueness_of :name, :message => "already exists", :scope =>"user_id" - + validates_format_of :name, :with => /^[^\/]*$/i, :message => "cannot contain the slash ('/') character" + def self.list_of(isdone=0) find(:all, :conditions => [ "done = ?" , true ], :order => "position ASC") end diff --git a/tracks/app/views/project/_project_form.rhtml b/tracks/app/views/project/_project_form.rhtml index 421a7b16..64ec4eca 100644 --- a/tracks/app/views/project/_project_form.rhtml +++ b/tracks/app/views/project/_project_form.rhtml @@ -1,7 +1,6 @@ <% @project = project_form %> -<%= error_messages_for 'project' %>
There were problems with the following fields:
This replaced the div
' + assert_rjs :replace, 'completely_replaced_div', /replaced the div/ + assert_rjs :replace_html, 'replaceable_div', "This goes inside the div" + assert_rjs :show, "post_1", "post_2", "post_3" + assert_rjs :sortable, 'sortable_item' + assert_rjs :toggle, "post_1", "post_2", "post_3" + assert_rjs :visual_effect, :highlight, "posts", :duration => '1.0' diff --git a/tracks/vendor/plugins/arts/init.rb b/tracks/vendor/plugins/arts/init.rb new file mode 100644 index 00000000..8993ba72 --- /dev/null +++ b/tracks/vendor/plugins/arts/init.rb @@ -0,0 +1,2 @@ +# Give testing some culture +Test::Unit::TestCase.send :include, Arts \ No newline at end of file diff --git a/tracks/vendor/plugins/arts/install.rb b/tracks/vendor/plugins/arts/install.rb new file mode 100644 index 00000000..a63be40f --- /dev/null +++ b/tracks/vendor/plugins/arts/install.rb @@ -0,0 +1 @@ +puts IO.read(File.join(File.dirname(__FILE__), 'README')) \ No newline at end of file diff --git a/tracks/vendor/plugins/arts/lib/arts.rb b/tracks/vendor/plugins/arts/lib/arts.rb new file mode 100644 index 00000000..ce02d986 --- /dev/null +++ b/tracks/vendor/plugins/arts/lib/arts.rb @@ -0,0 +1,110 @@ +module Arts + include ActionView::Helpers::PrototypeHelper + include ActionView::Helpers::ScriptaculousHelper + include ActionView::Helpers::JavaScriptHelper + + include ActionView::Helpers::UrlHelper + include ActionView::Helpers::TagHelper + + def assert_rjs(action, *args, &block) + respond_to?("assert_rjs_#{action}") ? + send("assert_rjs_#{action}", *args) : + assert(lined_response.include?(create_generator.send(action, *args, &block)), + generic_error(action, args)) + end + + def assert_no_rjs(action, *args, &block) + assert_raises(Test::Unit::AssertionFailedError) { assert_rjs(action, *args, &block) } + end + + def assert_rjs_insert_html(*args) + position = args.shift + item_id = args.shift + + content = extract_matchable_content(args) + + unless content.blank? + case content + when Regexp + assert_match Regexp.new("new Insertion\.#{position.to_s.camelize}(.*#{item_id}.*,.*#{content.source}.*);"), + @response.body + when String + assert lined_response.include?("new Insertion.#{position.to_s.camelize}(\"#{item_id}\", #{content});"), + "No insert_html call found for \n" + + " position: '#{position}' id: '#{item_id}' \ncontent: \n" + + "#{content}\n" + + "in response:\n#{lined_response}" + else + raise "Invalid content type" + end + else + assert_match Regexp.new("new Insertion\.#{position.to_s.camelize}(.*#{item_id}.*,.*?);"), + @response.body + end + end + + def assert_rjs_replace_html(*args) + div = args.shift + content = extract_matchable_content(args) + + unless content.blank? + case content + when Regexp + assert_match Regexp.new("Element.update(.*#{div}.*,.*#{content.source}.*);"), + @response.body + when String + assert lined_response.include?("Element.update(\"#{div}\", #{content});"), + "No replace_html call found on div: '#{div}' and content: \n#{content}\n" + + "in response:\n#{lined_response}" + else + raise "Invalid content type" + end + else + assert_match Regexp.new("Element.update(.*#{div}.*,.*?);"), @response.body + end + end + + def assert_rjs_replace(*args) + div = args.shift + content = extract_matchable_content(args) + + unless content.blank? + case content + when Regexp + assert_match Regexp.new("Element.replace(.*#{div}.*,.*#{content.source}.*);"), + @response.body + when String + assert lined_response.include?("Element.replace(\"#{div}\", #{content});"), + "No replace call found on div: '#{div}' and content: \n#{content}\n" + + "in response:\n#{lined_response}" + else + raise "Invalid content type" + end + else + assert_match Regexp.new("Element.replace(.*#{div}.*,.*?);"), @response.body + end + end + + protected + + def lined_response + @response.body.split("\n") + end + + def create_generator + block = Proc.new { |*args| yield *args if block_given? } + JavaScriptGenerator.new self, &block + end + + def generic_error(action, args) + "#{action} with args [#{args.join(" ")}] does not show up in response:\n#{lined_response}" + end + + def extract_matchable_content(args) + if args.size == 1 and args.first.is_a? Regexp + return args.first + else + return create_generator.send(:arguments_for_call, args) + end + end +end diff --git a/tracks/vendor/plugins/arts/meta.yml b/tracks/vendor/plugins/arts/meta.yml new file mode 100644 index 00000000..737fb011 --- /dev/null +++ b/tracks/vendor/plugins/arts/meta.yml @@ -0,0 +1,7 @@ +author: Kevin Clark +summary: RJS Assertion Plugin +homepage: http://glu.ttono.us +plugin: +version: 0.1 +license: MIT +rails_version: 1.1.2+ \ No newline at end of file diff --git a/tracks/vendor/plugins/arts/test/arts_test.rb b/tracks/vendor/plugins/arts/test/arts_test.rb new file mode 100644 index 00000000..c6019499 --- /dev/null +++ b/tracks/vendor/plugins/arts/test/arts_test.rb @@ -0,0 +1,361 @@ +$:.unshift(File.dirname(__FILE__) + '/../lib') + +require File.dirname(__FILE__) + '/../../../../config/environment' +require 'test/unit' +require 'rubygems' +require 'breakpoint' + +require 'action_controller/test_process' + +ActionController::Base.logger = nil +ActionController::Base.ignore_missing_templates = false +ActionController::Routing::Routes.reload rescue nil + +class ArtsController < ActionController::Base + def alert + render :update do |page| + page.alert 'This is an alert' + end + end + + def assign + render :update do |page| + page.assign 'a', '2' + end + end + + def call + render :update do |page| + page.call 'foo', 'bar', 'baz' + end + end + + def draggable + render :update do |page| + page.draggable 'my_image', :revert => true + end + end + + def drop_receiving + render :update do |page| + page.drop_receiving "my_cart", :url => { :controller => "cart", :action => "add" } + end + end + + def hide + render :update do |page| + page.hide 'some_div' + end + end + + def insert_html + render :update do |page| + page.insert_html :bottom, 'content', 'Stuff in the content div' + end + end + + def redirect + render :update do |page| + page.redirect_to :controller => 'sample', :action => 'index' + end + end + + def remove + render :update do |page| + page.remove 'offending_div' + end + end + + def replace + render :update do |page| + page.replace 'person_45', '