Skip to content

Commit

Permalink
DRY fake models for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Feb 2, 2017
1 parent c684f4f commit 0157608
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 37 deletions.
36 changes: 1 addition & 35 deletions actionview/test/actionpack/controller/render_test.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
require "abstract_unit"
require "active_model"
require "controller/fake_models"

class ApplicationController < ActionController::Base
self.view_paths = File.join(FIXTURE_LOAD_PATH, "actionpack")
end

Customer = Struct.new(:name, :id) do
extend ActiveModel::Naming
include ActiveModel::Conversion

undef_method :to_json

def to_xml(options = {})
if options[:builder]
options[:builder].name name
else
"<name>#{name}</name>"
end
end

def to_js(options = {})
"name: #{name.inspect}"
end
alias :to_text :to_js

def errors
[]
end

def persisted?
id.present?
end

def cache_key
name.to_s
end
end

module Quiz
#Models
Question = Struct.new(:name, :id) do
Expand All @@ -56,9 +25,6 @@ def new
end
end

class BadCustomer < Customer; end
class GoodCustomer < Customer; end

module Fun
class GamesController < ApplicationController
def hello_world; end
Expand Down
8 changes: 6 additions & 2 deletions actionview/test/lib/controller/fake_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ def errors
def persisted?
id.present?
end
end

class GoodCustomer < Customer
def cache_key
name.to_s
end
end

class BadCustomer < Customer; end
class GoodCustomer < Customer; end

Post = Struct.new(:title, :author_name, :body, :secret, :persisted, :written_on, :cost) do
extend ActiveModel::Naming
include ActiveModel::Conversion
Expand Down

0 comments on commit 0157608

Please sign in to comment.