-
Notifications
You must be signed in to change notification settings - Fork 27
Add support for mocking a form builder objects #40
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,5 @@ test/dummy/.sass-cache | |
| Gemfile.lock | ||
| test/tmp | ||
| *.gem | ||
|
|
||
| *.swp | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| AllCops: | ||
| RunRailsCops: true | ||
| Exclude: | ||
| - spec/dummy/db/schema.rb |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| module MountainView | ||
| module Helpers | ||
| class FormBuilder < ActionView::Base.default_form_builder | ||
| attr_accessor :model | ||
|
|
||
| def initialize(model) | ||
| @model = model | ||
| super(@model.class.model_name.param_key, | ||
| @model, | ||
| ActionView::Base.new, | ||
| {}) | ||
| rescue | ||
| super(@model.class.model_name.param_key, | ||
| @model, | ||
| ActionView::Base.new, | ||
| {}, | ||
| nil) | ||
| end | ||
|
|
||
| def to_json(_) | ||
| "form_for(#{model.to_json(nil)})" | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| require "delegate" | ||
|
|
||
| module MountainView | ||
| module Helpers | ||
| class ObjectWrapper < SimpleDelegator | ||
| attr_accessor :_attributes | ||
|
|
||
| def initialize(object, attributes) | ||
| super(object) | ||
| @_attributes = attributes | ||
| end | ||
|
|
||
| def class | ||
| __getobj__.class | ||
| end | ||
|
|
||
| def to_json(_) | ||
| "#{self.class.model_name}.new(#{@_attributes.deep_symbolize_keys})" | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <%= form.button "button text" %> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| :meta: 'There is a class with form builder object' | ||
| :stubs: | ||
| - | ||
| :id: 1 | ||
| :some_model: !mountain_view:Object | ||
| class: Something | ||
| attributes: | ||
| name: 'blabla' | ||
| :some_another_model: !Object | ||
| class: Something | ||
| attributes: | ||
| name: 'another blabla' | ||
| :form: | ||
| !Form | ||
| for: !Object | ||
| class: Something | ||
| attributes: | ||
| name: 'something name' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| class FormCustomButtonComponent < MountainView::Presenter | ||
| property :form | ||
| property :some_model | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| class Something < ActiveRecord::Base | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| class CreateSomethings < ActiveRecord::Migration | ||
| def change | ||
| create_table :somethings do |t| | ||
| t.string :name | ||
|
|
||
| t.timestamps null: false | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # encoding: UTF-8 | ||
| # This file is auto-generated from the current state of the database. Instead | ||
| # of editing this file, please use the migrations feature of Active Record to | ||
| # incrementally modify your database, and then regenerate this schema definition. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [81/80] |
||
| # | ||
| # Note that this schema.rb definition is the authoritative source for your | ||
| # database schema. If you need to create the application database on another | ||
| # system, you should be using db:schema:load, not running all the migrations | ||
| # from scratch. The latter is a flawed and unsustainable approach (the more migrations | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [86/80] |
||
| # you'll amass, the slower it'll run and the greater likelihood for issues). | ||
| # | ||
| # It's strongly recommended that you check this file into your version control system. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [86/80] |
||
|
|
||
| ActiveRecord::Schema.define(version: 20160427131303) do | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate every 3 digits in the integer portion of a number with underscores(_). |
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at block body beginning. |
||
| create_table "somethings", force: :cascade do |t| | ||
| t.string "name" | ||
| t.datetime "created_at", null: false | ||
| t.datetime "updated_at", null: false | ||
| end | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line detected at block body end. |
||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using
{...}for multi-line blocks.