mimoco 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/rake.yml +30 -0
  3. data/.gitignore +8 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.watchr +59 -0
  7. data/Gemfile +11 -0
  8. data/MIT-LICENSE +20 -0
  9. data/README.md +71 -0
  10. data/Rakefile +11 -0
  11. data/lib/mimoco/version.rb +8 -0
  12. data/lib/mimoco.rb +142 -0
  13. data/mimoco.gemspec +25 -0
  14. data/test/controllers/controllers_test.rb +16 -0
  15. data/test/controllers/orders_controller_test.rb +48 -0
  16. data/test/internal/app/controllers/application_controller.rb +3 -0
  17. data/test/internal/app/controllers/orders_controller.rb +74 -0
  18. data/test/internal/app/models/application_record.rb +3 -0
  19. data/test/internal/app/models/order.rb +11 -0
  20. data/test/internal/app/views/orders/_form.html.erb +22 -0
  21. data/test/internal/app/views/orders/_order.html.erb +7 -0
  22. data/test/internal/app/views/orders/_order.json.jbuilder +2 -0
  23. data/test/internal/app/views/orders/edit.html.erb +10 -0
  24. data/test/internal/app/views/orders/index.html.erb +14 -0
  25. data/test/internal/app/views/orders/index.json.jbuilder +1 -0
  26. data/test/internal/app/views/orders/new.html.erb +9 -0
  27. data/test/internal/app/views/orders/show.html.erb +10 -0
  28. data/test/internal/app/views/orders/show.json.jbuilder +1 -0
  29. data/test/internal/config/database.yml +3 -0
  30. data/test/internal/config/routes.rb +3 -0
  31. data/test/internal/db/migrate/20141016161801_create_orders.rb +10 -0
  32. data/test/internal/db/schema.rb +8 -0
  33. data/test/models/models_test.rb +77 -0
  34. data/test/test_helper.rb +12 -0
  35. metadata +118 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8e0963c7da7fd1d21ddabbee149892a7ca21875335d29c674ffdf6a19eeccaaa
4
+ data.tar.gz: 6a1c91af9b2cb82f7ca53d028bdea0b1b3d9e52f2b238f7564839f6b628db219
5
+ SHA512:
6
+ metadata.gz: 020fcf4c9d673af15d2395f39ba91343f424aa35324c477b083275154c0f3269d0b60ff3ac5c7ece19e78a813680dadc001011cd757e5de1ceb581cb408ea2c9
7
+ data.tar.gz: 78bb7afaadf170b233b8da4097e7d87c3926efac76380b0fa246be4a7808bad6db76823c41fa260868aa58c9558db53c6349c1720c4aacc1154a11867c2ac276
@@ -0,0 +1,30 @@
1
+ # see also https://github.com/whitequark/parser/blob/master/.github/workflows/test.yml
2
+ name: Rake
3
+
4
+ #on: [push, pull_request]
5
+ on: [push]
6
+
7
+ jobs:
8
+ test:
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ # os: [ubuntu-latest, macos-latest]
13
+ os: [ubuntu-latest]
14
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
15
+ # ruby: [2.5, 2.6, 2.7, '3.0', head, jruby, jruby-head, truffleruby, truffleruby-head]
16
+ ruby: ["3.0.3"]
17
+ test_command: ["bundle exec rake test"]
18
+ runs-on: ${{ matrix.os }}
19
+
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ - name: Bundle install
26
+ run: |
27
+ bundle config path /home/runner/bundle
28
+ bundle install
29
+ bundle update
30
+ - run: ${{ matrix.test_command }}
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .bundle/
2
+ coverage/
3
+
4
+ *.gem
5
+ *.log
6
+ *.lock
7
+
8
+ **/db/*.sqlite3
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rails-7.0
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.0.3
data/.watchr ADDED
@@ -0,0 +1,59 @@
1
+ TESTING = %w[test]
2
+ HH = "#" * 22 unless defined?(HH)
3
+ H = "#" * 5 unless defined?(H)
4
+
5
+ def usage
6
+ puts <<-EOS
7
+ Ctrl-\\ or ctrl-4 Running all tests
8
+ Ctrl-C Exit
9
+ EOS
10
+ end
11
+
12
+ def run(cmd)
13
+ puts "#{HH} #{Time.now} #{HH}"
14
+ puts "#{H} #{cmd}"
15
+ system "/usr/bin/time --format '#{HH} Elapsed time %E' #{cmd}"
16
+ end
17
+
18
+ def run_it(type, file)
19
+ case type
20
+ when "test" then run %(bundle exec ruby -I test #{file})
21
+ # when 'spec'; run %(rspec -X #{file})
22
+ else; puts "#{H} unknown type: #{type}, file: #{file}"
23
+ end
24
+ end
25
+
26
+ def run_all_tests
27
+ puts "\n#{HH} Running all tests #{HH}\n"
28
+ TESTING.each { |dir| run "bundle exec rake #{dir}" if File.exist?(dir) }
29
+ end
30
+
31
+ def run_matching_files(base)
32
+ base = base.split("_").first
33
+ TESTING.each { |type|
34
+ files = Dir["#{type}/**/*.rb"].select { |file| file =~ /#{base}_.*\.rb/ }
35
+ run_it type, files.join(" ") unless files.empty?
36
+ }
37
+ end
38
+
39
+ TESTING.each { |type|
40
+ watch("#{type}/#{type}_helper\.rb") { run_all_tests }
41
+ watch("lib/.*\.rb") { run_all_tests }
42
+ watch("#{type}/.*/*_#{type}\.rb") { |match| run_it type, match[0] }
43
+ watch("#{type}/data/(.*)\.rb") { |match|
44
+ m1 = match[1]
45
+ run_matching_files("#{type}/#{m1}/#{m1}_#{type}.rb")
46
+ }
47
+ }
48
+
49
+ %w[rb erb haml slim].each { |type|
50
+ watch(".*/(.*)\.#{type}") { |match|
51
+ run_matching_files(match[1])
52
+ }
53
+ }
54
+
55
+ # Ctrl-\ or ctrl-4
56
+ Signal.trap("QUIT") { run_all_tests }
57
+ # Ctrl-C
58
+ Signal.trap("INT") { abort("Interrupted\n") }
59
+ usage
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ gem "rails"
5
+
6
+ group :test do
7
+ gem "observr"
8
+ gem "standard", require: false
9
+ gem "simplecov", require: false
10
+ gem "ricecream"
11
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2021 Dittmar Krall - www.matique.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # MiMoCo
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/miau.png)](http://badge.fury.io/rb/mimoco)
4
+
5
+ Mimoco (MInitest MOdels COntrollers) DRY
6
+ your tests by specifying some (trivial) of them via table.
7
+
8
+ Mimoco doesn't replace the "assert"s of MiniTest.
9
+ It is more a kind of a quick and dirty check.
10
+ Still, it has demonstrated to be useful, in particular,
11
+ to detect code changes which often went unseen.
12
+
13
+ ## Installation
14
+
15
+ ~~~ ruby
16
+ # Gemfile
17
+ gem "mimoco"
18
+ ~~~
19
+ and run "bundle install".
20
+
21
+ ## Usage for Models
22
+
23
+ ~~~ ruby
24
+ require "test_helper"
25
+ require "mimoco"
26
+
27
+ class ModelsTest < Minitest::Test
28
+ def test_some
29
+ models = {
30
+ Order => {
31
+ valid: {name: "Name", qty: 123},
32
+ invalid: {qty: :abc},
33
+ class_methods: %i[class_method],
34
+ call_class_methods: %i[class_method],
35
+ public_methods: %i[public_method],
36
+ call_public_methods: %i[public_method]
37
+ },
38
+ Article => ...
39
+ }
40
+
41
+ check_models models
42
+ end
43
+ end
44
+ ~~~
45
+
46
+ Furthermore, "valids" and "invalids" accepts an array
47
+ of hashes to create models to be checked.
48
+
49
+ "call_public_methods" requires a "valid" item
50
+ to instantiated a model used to applicate the methods.
51
+
52
+ ## Usage for Controllers
53
+
54
+ ~~~ ruby
55
+ require "test_helper"
56
+ require "mimoco"
57
+
58
+ class ControllersTest < ActionDispatch::IntegrationTest
59
+ def test_some
60
+ controllers = {
61
+ OrdersController => {
62
+ respond_to: %i[create destroy edit index new show update],
63
+ class_methods: %i[class_method],
64
+ call_class_methods: %i[class_method],
65
+ public_methods: %i[create destroy edit index new show update]
66
+ }
67
+ }
68
+ check_controllers controllers
69
+ end
70
+ end
71
+ ~~~
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "rake/testtask"
2
+
3
+ desc "Run the tests."
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "lib"
6
+ t.libs << "test"
7
+ t.pattern = "test/**/*_test.rb"
8
+ t.verbose = false
9
+ end
10
+
11
+ task default: :test
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ # rubocop: disable all
3
+
4
+ module Mimoco
5
+ VERSION = "0.2.0" # 2022-01-06
6
+ # VERSION = "0.1.0" # 2022-01-03
7
+ # VERSION = "0.0.1" # 2021-12-29
8
+ end
data/lib/mimoco.rb ADDED
@@ -0,0 +1,142 @@
1
+ require "minitest"
2
+
3
+ module Minitest
4
+ module Checks
5
+ def check_models(data)
6
+ Models.run data, self
7
+ end
8
+
9
+ def check_controllers(data)
10
+ Controllers.run data, self
11
+ end
12
+
13
+ class ValidMissingError < StandardError; end
14
+
15
+ class Base
16
+ attr_accessor :minitest, :klass, :klass_hash, :where
17
+
18
+ def self.run(data, minitest)
19
+ @minitest = minitest
20
+ data.each do |klass, hash|
21
+ @klass = klass
22
+ @klass_hash = hash
23
+ hash.each do |function, value|
24
+ @where = "#{klass}##{function}"
25
+ send(function, value)
26
+ end
27
+ end
28
+ end
29
+
30
+ def self.check_equal(expected, actual, msg = nil)
31
+ expected = expected.sort.map(&:to_sym)
32
+ actual = actual.sort.map(&:to_sym)
33
+ msg = msg ? "#{@where}: #{msg}" : @where
34
+ @minitest.assert_equal expected, actual, msg
35
+ end
36
+
37
+ def self.check_no_nil(actual, msg = nil)
38
+ msg = msg ? "#{@where}: #{msg}" : @where
39
+ @minitest.refute_nil actual, msg
40
+ end
41
+ end
42
+
43
+ class Models < Base
44
+ def self.valid(params)
45
+ valids([params])
46
+ end
47
+
48
+ def self.valids(arr)
49
+ arr.each { |params| one_valid(params) }
50
+ end
51
+
52
+ def self.invalid(params)
53
+ invalids([params])
54
+ end
55
+
56
+ def self.invalids(arr)
57
+ arr.each { |params| one_invalid(params) }
58
+ end
59
+
60
+ def self.class_methods(expected)
61
+ cls = @klass.methods(false).sort
62
+ cls.delete_if { |x| /^_/ =~ x }
63
+ cls.delete_if { |x| /^(after|before|find_by)_/ =~ x }
64
+ cls -= %i[column_headers attribute_type_decorations
65
+ attributes_to_define_after_schema_loads
66
+ default_scope_override defined_enums]
67
+ check_equal expected, cls
68
+ end
69
+
70
+ # call class methods; don't check result
71
+ def self.call_class_methods(methods)
72
+ methods.each { |meth|
73
+ check_no_nil @klass.send(meth), "<#{meth}> should return no nil"
74
+ }
75
+ end
76
+
77
+ def self.public_methods(expected)
78
+ cls = @klass.public_instance_methods(false).sort
79
+ cls -= %i[autosave_associated_records_for_projects
80
+ validate_associated_records_for_projects]
81
+ check_equal expected, cls
82
+ end
83
+
84
+ # call_public_methods; don't check result
85
+ def self.call_public_methods(methods)
86
+ klass_params = @klass_hash[:valid] || @klass_hash[:valids]&.first
87
+ raise ValidMissingError unless klass_params
88
+
89
+ methods.each { |meth|
90
+ row, msg = @klass.create(klass_params)
91
+ check_no_nil row.send(meth), "<#{meth}> should return no nil"
92
+ }
93
+ end
94
+
95
+ def self.one_valid(params)
96
+ row, msg = create_model(params)
97
+ @minitest.assert row.valid?, "#{msg} #{row.errors.full_messages}"
98
+ end
99
+
100
+ def self.one_invalid(params)
101
+ row, msg = create_model(params)
102
+ @minitest.refute row.valid?, "#{msg} expected to be invalid"
103
+ end
104
+
105
+ def self.create_model(params)
106
+ row = @klass.create(params)
107
+ [row, "#{@klass}: #{params}"]
108
+ end
109
+ end
110
+
111
+ class Controllers < Base
112
+ def self.respond_to(methods)
113
+ instance = @klass.new
114
+ methods.each { |method|
115
+ msg = "#{@klass} should respond to #{method}"
116
+ @minitest.assert instance.respond_to?(method), msg
117
+ }
118
+ end
119
+
120
+ def self.class_methods(expected)
121
+ cls = @klass.methods(false).sort
122
+ cls -= %i[__callbacks helpers_path middleware_stack]
123
+ check_equal expected, cls
124
+ end
125
+
126
+ def self.call_class_methods(methods)
127
+ methods.each { |meth|
128
+ check_no_nil @klass.send(meth), "<#{meth}> should return no nil"
129
+ }
130
+ end
131
+
132
+ def self.public_methods(expected)
133
+ cls = @klass.new.public_methods(false).sort
134
+ check_equal expected, cls
135
+ end
136
+ end
137
+ end
138
+
139
+ class Test
140
+ include Checks
141
+ end
142
+ end
data/mimoco.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "mimoco/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mimoco"
7
+ s.version = Mimoco::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "Mimoco: some minitests for models and controllers"
10
+ s.description = "Some testing for models and controllers"
11
+ s.authors = ["Dittmar Krall"]
12
+ s.email = ["dittmar.krall@matique.com"]
13
+ s.homepage = "http://matique.com"
14
+ s.license = "MIT"
15
+
16
+ # s.metadata["source_code_uri"] = "https://github.com/matique/stones2"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "combustion"
22
+
23
+ s.add_development_dependency "minitest"
24
+ s.add_development_dependency "sqlite3"
25
+ end
@@ -0,0 +1,16 @@
1
+ require "test_helper"
2
+ require "mimoco"
3
+
4
+ class ControllersTest < ActionDispatch::IntegrationTest
5
+ def test_some
6
+ controllers = {
7
+ OrdersController => {
8
+ respond_to: %i[create destroy edit index new show update],
9
+ class_methods: %i[class_method],
10
+ call_class_methods: %i[class_method],
11
+ public_methods: %i[create destroy edit index new show update]
12
+ }
13
+ }
14
+ check_controllers controllers
15
+ end
16
+ end
@@ -0,0 +1,48 @@
1
+ require "test_helper"
2
+
3
+ class OrdersControllerTest < ActionDispatch::IntegrationTest
4
+ setup do
5
+ @order = Order.create!(name: "Name", qty: 123)
6
+ end
7
+
8
+ test "should get index" do
9
+ get orders_url
10
+ assert_response :success
11
+ end
12
+
13
+ test "should get new" do
14
+ get new_order_url
15
+ assert_response :success
16
+ end
17
+
18
+ test "should create order" do
19
+ assert_difference("Order.count") do
20
+ post orders_url, params: {order: {name: @order.name, qty: 234}}
21
+ end
22
+
23
+ assert_redirected_to order_url(Order.last)
24
+ end
25
+
26
+ test "should show order" do
27
+ get order_url(@order)
28
+ assert_response :success
29
+ end
30
+
31
+ test "should get edit" do
32
+ get edit_order_url(@order)
33
+ assert_response :success
34
+ end
35
+
36
+ test "should update order" do
37
+ patch order_url(@order), params: {order: {name: @order.name}}
38
+ assert_redirected_to order_url(@order)
39
+ end
40
+
41
+ test "should destroy order" do
42
+ assert_difference("Order.count", -1) do
43
+ delete order_url(@order)
44
+ end
45
+
46
+ assert_redirected_to orders_url
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
@@ -0,0 +1,74 @@
1
+ class OrdersController < ApplicationController
2
+ before_action :set_order, only: %i[show edit update destroy]
3
+
4
+ def self.class_method
5
+ "just for testing purposes"
6
+ end
7
+
8
+ # GET /orders or /orders.json
9
+ def index
10
+ @orders = Order.all
11
+ end
12
+
13
+ # GET /orders/1 or /orders/1.json
14
+ def show
15
+ end
16
+
17
+ # GET /orders/new
18
+ def new
19
+ @order = Order.new
20
+ end
21
+
22
+ # GET /orders/1/edit
23
+ def edit
24
+ end
25
+
26
+ # POST /orders or /orders.json
27
+ def create
28
+ @order = Order.new(order_params)
29
+
30
+ respond_to do |format|
31
+ if @order.save
32
+ format.html { redirect_to @order, notice: "Order was successfully created." }
33
+ format.json { render :show, status: :created, location: @order }
34
+ else
35
+ format.html { render :new, status: :unprocessable_entity }
36
+ format.json { render json: @order.errors, status: :unprocessable_entity }
37
+ end
38
+ end
39
+ end
40
+
41
+ # PATCH/PUT /orders/1 or /orders/1.json
42
+ def update
43
+ respond_to do |format|
44
+ if @order.update(order_params)
45
+ format.html { redirect_to @order, notice: "Order was successfully updated." }
46
+ format.json { render :show, status: :ok, location: @order }
47
+ else
48
+ format.html { render :edit, status: :unprocessable_entity }
49
+ format.json { render json: @order.errors, status: :unprocessable_entity }
50
+ end
51
+ end
52
+ end
53
+
54
+ # DELETE /orders/1 or /orders/1.json
55
+ def destroy
56
+ @order.destroy
57
+ respond_to do |format|
58
+ format.html { redirect_to orders_url, notice: "Order was successfully destroyed." }
59
+ format.json { head :no_content }
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ # Use callbacks to share common setup or constraints between actions.
66
+ def set_order
67
+ @order = Order.find(params[:id])
68
+ end
69
+
70
+ # Only allow a list of trusted parameters through.
71
+ def order_params
72
+ params.require(:order).permit(:name, :qty)
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ primary_abstract_class
3
+ end
@@ -0,0 +1,11 @@
1
+ class Order < ApplicationRecord
2
+ validates :qty, numericality: {only_integer: true}
3
+
4
+ def public_method
5
+ "#{name}: #{qty}"
6
+ end
7
+
8
+ def self.class_method
9
+ true
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ <%= form_with(model: order) do |form| %>
2
+ <% if order.errors.any? %>
3
+ <div style="color: red">
4
+ <h2><%= pluralize(order.errors.count, "error") %> prohibited this order from being saved:</h2>
5
+
6
+ <ul>
7
+ <% order.errors.each do |error| %>
8
+ <li><%= error.full_message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div>
15
+ <%= form.label :name, style: "display: block" %>
16
+ <%= form.text_field :name %>
17
+ </div>
18
+
19
+ <div>
20
+ <%= form.submit %>
21
+ </div>
22
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <div id="<%= dom_id order %>">
2
+ <p>
3
+ <strong>Name:</strong>
4
+ <%= order.name %>
5
+ </p>
6
+
7
+ </div>
@@ -0,0 +1,2 @@
1
+ json.extract! order, :id, :name, :created_at, :updated_at
2
+ json.url order_url(order, format: :json)
@@ -0,0 +1,10 @@
1
+ <h1>Editing order</h1>
2
+
3
+ <%= render "form", order: @order %>
4
+
5
+ <br>
6
+
7
+ <div>
8
+ <%= link_to "Show this order", @order %> |
9
+ <%= link_to "Back to orders", orders_path %>
10
+ </div>
@@ -0,0 +1,14 @@
1
+ <p style="color: green"><%= notice %></p>
2
+
3
+ <h1>Orders</h1>
4
+
5
+ <div id="orders">
6
+ <% @orders.each do |order| %>
7
+ <%= render order %>
8
+ <p>
9
+ <%= link_to "Show this order", order %>
10
+ </p>
11
+ <% end %>
12
+ </div>
13
+
14
+ <%= link_to "New order", new_order_path %>
@@ -0,0 +1 @@
1
+ json.array! @orders, partial: "orders/order", as: :order
@@ -0,0 +1,9 @@
1
+ <h1>New order</h1>
2
+
3
+ <%= render "form", order: @order %>
4
+
5
+ <br>
6
+
7
+ <div>
8
+ <%= link_to "Back to orders", orders_path %>
9
+ </div>
@@ -0,0 +1,10 @@
1
+ <p style="color: green"><%= notice %></p>
2
+
3
+ <%= render @order %>
4
+
5
+ <div>
6
+ <%= link_to "Edit this order", edit_order_path(@order) %> |
7
+ <%= link_to "Back to orders", orders_path %>
8
+
9
+ <%= button_to "Destroy this order", @order, method: :delete %>
10
+ </div>
@@ -0,0 +1 @@
1
+ json.partial! "orders/order", order: @order
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/test.sqlite3
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ resources :orders
3
+ end
@@ -0,0 +1,10 @@
1
+ class CreateOrders < ActiveRecord::Migration
2
+ def change
3
+ create_table :orders do |t|
4
+ t.string :name
5
+ t.string :qty
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ ActiveRecord::Schema.define(version: 20141016161801) do
2
+ create_table "orders", force: true do |t|
3
+ t.string "name"
4
+ t.string "qty"
5
+ t.datetime "created_at", null: false
6
+ t.datetime "updated_at", null: false
7
+ end
8
+ end
@@ -0,0 +1,77 @@
1
+ require "test_helper"
2
+ require "mimoco"
3
+
4
+ class ModelsTest < Minitest::Test
5
+ def test_valid
6
+ models = {Order => {valid: {name: "Name", qty: 123}}}
7
+ check_models models
8
+ end
9
+
10
+ def test_valids
11
+ models = {
12
+ Order => {
13
+ valids: [
14
+ {name: "Name", qty: 123},
15
+ {qty: 123}
16
+ ]
17
+ }
18
+ }
19
+ check_models models
20
+ end
21
+
22
+ def test_invalid
23
+ models = {Order => {invalid: {qty: :abc}}}
24
+ check_models models
25
+ end
26
+
27
+ def test_invalids
28
+ models = {
29
+ Order => {
30
+ invalids: [
31
+ {qty: :abc},
32
+ {name: "Name", qty: :def}
33
+ ]
34
+ }
35
+ }
36
+ check_models models
37
+ end
38
+
39
+ def test_class_methods
40
+ models = {Order => {class_methods: %i[class_method]}}
41
+ check_models models
42
+ end
43
+
44
+ def test_call_class_methods
45
+ models = {Order => {call_class_methods: %i[class_method]}}
46
+ check_models models
47
+ end
48
+
49
+ def test_public_methods
50
+ models = {Order => {public_methods: %i[public_method]}}
51
+ check_models models
52
+ end
53
+
54
+ def test_call_public_methods
55
+ models = {
56
+ Order => {
57
+ valid: {name: "Name", qty: 123},
58
+ call_public_methods: %i[public_method]
59
+ }
60
+ }
61
+ check_models models
62
+ end
63
+
64
+ def test_several
65
+ models = {
66
+ Order => {
67
+ valid: {name: "Name", qty: 123},
68
+ invalid: {qty: :abc},
69
+ class_methods: %i[class_method],
70
+ call_class_methods: %i[class_method],
71
+ public_methods: %i[public_method],
72
+ call_public_methods: %i[public_method]
73
+ }
74
+ }
75
+ check_models models
76
+ end
77
+ end
@@ -0,0 +1,12 @@
1
+ if ENV["COVERAGE"]
2
+ require "simplecov"
3
+ SimpleCov.start do
4
+ add_filter "/test/"
5
+ end
6
+ end
7
+
8
+ require "combustion"
9
+ Combustion.path = "test/internal"
10
+ Combustion.initialize! :active_record
11
+
12
+ require "rails/test_help"
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mimoco
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Dittmar Krall
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: combustion
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Some testing for models and controllers
56
+ email:
57
+ - dittmar.krall@matique.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".github/workflows/rake.yml"
63
+ - ".gitignore"
64
+ - ".ruby-gemset"
65
+ - ".ruby-version"
66
+ - ".watchr"
67
+ - Gemfile
68
+ - MIT-LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - lib/mimoco.rb
72
+ - lib/mimoco/version.rb
73
+ - mimoco.gemspec
74
+ - test/controllers/controllers_test.rb
75
+ - test/controllers/orders_controller_test.rb
76
+ - test/internal/app/controllers/application_controller.rb
77
+ - test/internal/app/controllers/orders_controller.rb
78
+ - test/internal/app/models/application_record.rb
79
+ - test/internal/app/models/order.rb
80
+ - test/internal/app/views/orders/_form.html.erb
81
+ - test/internal/app/views/orders/_order.html.erb
82
+ - test/internal/app/views/orders/_order.json.jbuilder
83
+ - test/internal/app/views/orders/edit.html.erb
84
+ - test/internal/app/views/orders/index.html.erb
85
+ - test/internal/app/views/orders/index.json.jbuilder
86
+ - test/internal/app/views/orders/new.html.erb
87
+ - test/internal/app/views/orders/show.html.erb
88
+ - test/internal/app/views/orders/show.json.jbuilder
89
+ - test/internal/config/database.yml
90
+ - test/internal/config/routes.rb
91
+ - test/internal/db/migrate/20141016161801_create_orders.rb
92
+ - test/internal/db/schema.rb
93
+ - test/models/models_test.rb
94
+ - test/test_helper.rb
95
+ homepage: http://matique.com
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.2.32
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: 'Mimoco: some minitests for models and controllers'
118
+ test_files: []