aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/lib')
-rw-r--r--actionpack/test/lib/controller/fake_models.rb33
-rw-r--r--actionpack/test/lib/fixture_template.rb17
2 files changed, 28 insertions, 22 deletions
diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb
index 7346cb22bc..bf3e175f1f 100644
--- a/actionpack/test/lib/controller/fake_models.rb
+++ b/actionpack/test/lib/controller/fake_models.rb
@@ -6,10 +6,6 @@ class Customer < Struct.new(:name, :id)
undef_method :to_json
- def to_param
- id.to_s
- end
-
def to_xml(options={})
if options[:builder]
options[:builder].name name
@@ -21,13 +17,14 @@ class Customer < Struct.new(:name, :id)
def to_js(options={})
"name: #{name.inspect}"
end
+ alias :to_text :to_js
def errors
[]
end
- def destroyed?
- false
+ def persisted?
+ id.present?
end
end
@@ -42,8 +39,8 @@ module Quiz
extend ActiveModel::Naming
include ActiveModel::Conversion
- def to_param
- id.to_s
+ def persisted?
+ id.present?
end
end
@@ -58,12 +55,12 @@ class Post < Struct.new(:title, :author_name, :body, :secret, :written_on, :cost
alias_method :secret?, :secret
- def new_record=(boolean)
- @new_record = boolean
+ def persisted=(boolean)
+ @persisted = boolean
end
- def new_record?
- @new_record
+ def persisted?
+ @persisted
end
attr_accessor :author
@@ -83,8 +80,9 @@ class Comment
attr_reader :id
attr_reader :post_id
def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
+ def to_key; id ? [id] : nil end
def save; @id = 1; @post_id = 1 end
- def new_record?; @id.nil? end
+ def persisted?; @id.present? end
def to_param; @id; end
def name
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
@@ -102,8 +100,9 @@ class Tag
attr_reader :id
attr_reader :post_id
def initialize(id = nil, post_id = nil); @id, @post_id = id, post_id end
+ def to_key; id ? [id] : nil end
def save; @id = 1; @post_id = 1 end
- def new_record?; @id.nil? end
+ def persisted?; @id.present? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
@@ -121,8 +120,9 @@ class CommentRelevance
attr_reader :id
attr_reader :comment_id
def initialize(id = nil, comment_id = nil); @id, @comment_id = id, comment_id end
+ def to_key; id ? [id] : nil end
def save; @id = 1; @comment_id = 1 end
- def new_record?; @id.nil? end
+ def persisted?; @id.present? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
@@ -136,8 +136,9 @@ class TagRelevance
attr_reader :id
attr_reader :tag_id
def initialize(id = nil, tag_id = nil); @id, @tag_id = id, tag_id end
+ def to_key; id ? [id] : nil end
def save; @id = 1; @tag_id = 1 end
- def new_record?; @id.nil? end
+ def persisted?; @id.present? end
def to_param; @id; end
def value
@id.nil? ? "new #{self.class.name.downcase}" : "#{self.class.name.downcase} ##{@id}"
diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb
index 6b9e7c5270..02248d84ad 100644
--- a/actionpack/test/lib/fixture_template.rb
+++ b/actionpack/test/lib/fixture_template.rb
@@ -1,23 +1,28 @@
module ActionView #:nodoc:
class FixtureResolver < PathResolver
- def initialize(hash = {}, options = {})
- super(options)
+ attr_reader :hash
+
+ def initialize(hash = {})
+ super()
@hash = hash
end
private
- def query(path, exts)
+ def query(partial, path, exts)
query = Regexp.escape(path)
exts.each do |ext|
- query << '(?:' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << ')'
+ query << '(' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << ')'
end
templates = []
@hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source|
- templates << Template.new(source, path, *path_to_details(path))
+ handler, format = extract_handler_and_format(path)
+ templates << Template.new(source, path, handler,
+ :partial => partial, :virtual_path => path, :format => format)
end
- templates.sort_by {|t| -t.details.values.compact.size }
+
+ templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
end
end