standard-library / microform Goto Github PK
View Code? Open in Web Editor NEWTiny form object pattern for Rails
License: MIT License
Tiny form object pattern for Rails
License: MIT License
Seems like the generated files should be tested somehow, though not sure at this point how that might work (especially testing the test file)โฆ
Should microform also have an "install" generator that adds an ApplicationForm class to your project?
Or, taking a step back, how can some of the generic functionality like the respond_to?
and other delegation method. This could either be a parent class, or a mix-in module, or simply repeated in each form class.
The next question is, if functionality is shared in either of those way, does that mean that the instance variable needs to get more generic:
def initialize project
@project = project
end
# vs
def initialize record
@record = record
end
Or, is there some way that the instance variable is configured. This could be too clever:
class ProjectForm
include Micrform::Form[:project]
end
Or, the instance variable could be inferred from the form name, e.g. ProjectForm
assumes there will be a @project
instance variable assigned in the initializer.
Do these "solutions" jump trough too many hoops to just avoid renaming the attribute to the more generic record
?
Of course, the project NEEDS a logo.
Since using plain ruby objects is a big benefit to how easy it is to test, there should be a brief section about testing included.
I started working on a potential syntax for this, which I'll wrap up and post as a proposal in this issue.
Use the [email protected] email address instead of @skwak's personal email address ๐
Add:
Anything else?
Writing a test with the test helper for the following test will pass, while executing the code in the controller will actually raise an exception:
class FooController
def create
submit FooForm, Foo.new, params, extra_argument
end
end
class FooControllerTest
def test_should_create
assert_submits OrderForm, stub: order_double do
post foos_url
end
end
end
The stub that replaces the submit method verifies that the first argument is the correct form, but not that the second and third arguments are present (and no more than that).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.