Skip to content

Remove skip statements from scaffold controller tests during smoke #1680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions example_app_generator/generate_stuff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,9 @@ def using_source_path(path)
'config.warnings = false'
gsub_file '.rspec', '--warnings', ''

# Remove skips so we can test controller specs work
gsub_file 'spec/controllers/gadgets_controller_spec.rb',
'skip("Add a hash of attributes valid for your model")',
'{}'

final_tasks
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,18 @@ def count
alias_method :size, :count
alias_method :length, :count

def last
all.last
end

def find(id)
id = id.to_i
all.find { |record| record.id == id } || raise
end

def create!(attributes = {})
with_id = { :id => next_id, :persisted => true }
all << record = new(with_id.merge(attributes))
record = new(attributes)
record.save
record
end

Expand All @@ -38,16 +47,50 @@ class Model
include ::ActiveModel::Validations

def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
assign_attributes(attributes)
end
end

attr_accessor :id, :persisted

alias_method :persisted?, :persisted

def update(attributes)
assign_attributes(attributes)
save
end

alias_method :update_attributes, :update

def assign_attributes(attributes)
attributes.each do |name, value|
__send__("#{name}=", value)
end
end

def save(*)
self.id = self.class.next_id
self.class.all << self
true
end

def destroy
self.class.all.delete(self)
true
end

def reload(*)
self
end

def ==(other)
other.is_a?(self.class) && id == other.id
end

def persisted?
!id.nil?
end

def new_record?
!persisted?
end
Expand Down