Mocked out ActiveRecord for testing plugin
I mentioned this in my previous post, but to make my plugin easier to test I tried to make it not need to touch the DB, which was interesting to do, given that scaffold_resource is very much tied to a model. This was a big inspiration and this the final (as of now) result:
class Resource < ActiveRecord::Base
@@count = 1
def self.count() @@count end
def self.columns() @columns ||= []; end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
end
def self.find(param)
return param == :all ? [Resource.new{ |m| m.id = 1; m.name = 'bob' }] : Resource.new{ |m| m.id = 1; m.name = 'bob' }
end
def save() @@count += 1 and return true if valid? end
def destroy() @@count -= 1 end
column :name, :string
end

Articles via rss or email