diff --git a/.gitignore b/.gitignore index 417560f..102b015 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/.bundle/ +.bundle/ /.yardoc /Gemfile.lock /_yardoc/ @@ -9,3 +9,4 @@ /log tmp .DS_Store +log/ diff --git a/.travis.yml b/.travis.yml index 4872a16..97e7558 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ env: - "RAILS_VERSION=4.2" - "RAILS_VERSION=5.0" - "RAILS_VERSION=5.1" + - "RAILS_VERSION=5.2" matrix: fast_finish: true exclude: diff --git a/test/rails4.2/.gitignore b/test/rails4.2/.gitignore deleted file mode 100644 index 280c06b..0000000 --- a/test/rails4.2/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# See https://help.github.com/articles/ignoring-files for more about ignoring files. -# -# If you find yourself ignoring temporary files generated by your text editor -# or operating system, you probably want to add a global ignore instead: -# git config --global core.excludesfile '~/.gitignore_global' - -# Ignore bundler config. -/.bundle - -# Ignore all logfiles and tempfiles. -/log/* -!/log/.keep -/tmp \ No newline at end of file diff --git a/test/rails5.0/.gitignore b/test/rails5.0/.gitignore deleted file mode 100644 index 280c06b..0000000 --- a/test/rails5.0/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# See https://help.github.com/articles/ignoring-files for more about ignoring files. -# -# If you find yourself ignoring temporary files generated by your text editor -# or operating system, you probably want to add a global ignore instead: -# git config --global core.excludesfile '~/.gitignore_global' - -# Ignore bundler config. -/.bundle - -# Ignore all logfiles and tempfiles. -/log/* -!/log/.keep -/tmp \ No newline at end of file diff --git a/test/rails5.1/.gitignore b/test/rails5.1/.gitignore deleted file mode 100644 index 280c06b..0000000 --- a/test/rails5.1/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# See https://help.github.com/articles/ignoring-files for more about ignoring files. -# -# If you find yourself ignoring temporary files generated by your text editor -# or operating system, you probably want to add a global ignore instead: -# git config --global core.excludesfile '~/.gitignore_global' - -# Ignore bundler config. -/.bundle - -# Ignore all logfiles and tempfiles. -/log/* -!/log/.keep -/tmp \ No newline at end of file diff --git a/test/rails5.2/Gemfile b/test/rails5.2/Gemfile new file mode 100644 index 0000000..69d0111 --- /dev/null +++ b/test/rails5.2/Gemfile @@ -0,0 +1,20 @@ +source 'https://rubygems.org' + +gem 'rails', '~> 5.2.0' + +gem "my_engine", path: "engines/my_engine" + +gem 'sass-rails' +gem "sprockets" + +group :development, :test do + gem "minitest-spec-rails" + gem "capybara_minitest_spec" +end + +gem "cells", ">= 4.1.6" +# gem "cells", path: "../../../cells"# ">= 4.1.0" +gem "cells-rails", path: "../../../cells-rails"# ">= 4.1.0" +gem "cells-erb" +gem "simple_form" +gem "formtastic" diff --git a/test/rails5.2/Gemfile.lock b/test/rails5.2/Gemfile.lock new file mode 100644 index 0000000..abb71ce --- /dev/null +++ b/test/rails5.2/Gemfile.lock @@ -0,0 +1,198 @@ +PATH + remote: ../.. + specs: + cells-rails (0.0.9) + actionpack (>= 3.0) + cells (>= 4.1.6, < 5.0.0) + +PATH + remote: engines/my_engine + specs: + my_engine (0.0.1) + cells (>= 4.0.0.beta5) + cells-erb + rails (>= 4.2.1) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.2.0) + actionpack (= 5.2.0) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.0) + actionpack (= 5.2.0) + actionview (= 5.2.0) + activejob (= 5.2.0) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.2.0) + actionview (= 5.2.0) + activesupport (= 5.2.0) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.2.0) + activesupport (= 5.2.0) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.2.0) + activesupport (= 5.2.0) + globalid (>= 0.3.6) + activemodel (5.2.0) + activesupport (= 5.2.0) + activerecord (5.2.0) + activemodel (= 5.2.0) + activesupport (= 5.2.0) + arel (>= 9.0) + activestorage (5.2.0) + actionpack (= 5.2.0) + activerecord (= 5.2.0) + marcel (~> 0.3.1) + activesupport (5.2.0) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) + arel (9.0.0) + builder (3.2.3) + capybara (3.0.2) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + xpath (~> 3.0) + capybara_minitest_spec (1.0.7) + capybara (>= 2) + minitest (>= 4) + cells (4.1.7) + declarative-builder (< 0.2.0) + declarative-option (< 0.2.0) + tilt (>= 1.4, < 3) + uber (< 0.2.0) + cells-erb (0.1.0) + cells (~> 4.0) + erbse (>= 0.1.1) + concurrent-ruby (1.0.5) + crass (1.0.4) + declarative-builder (0.1.0) + declarative-option (< 0.2.0) + declarative-option (0.1.0) + erbse (0.1.3) + temple + erubi (1.7.1) + ffi (1.9.23) + formtastic (3.1.5) + actionpack (>= 3.2.13) + globalid (0.4.1) + activesupport (>= 4.2.0) + i18n (1.0.1) + concurrent-ruby (~> 1.0) + loofah (2.2.2) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.7.0) + mini_mime (>= 0.1.1) + marcel (0.3.2) + mimemagic (~> 0.3.2) + method_source (0.9.0) + mimemagic (0.3.2) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + minitest (5.11.3) + minitest-spec-rails (5.4.0) + minitest (~> 5.0) + rails (>= 4.1) + nio4r (2.3.0) + nokogiri (1.8.2) + mini_portile2 (~> 2.3.0) + public_suffix (3.0.2) + rack (2.0.5) + rack-test (1.0.0) + rack (>= 1.0, < 3) + rails (5.2.0) + actioncable (= 5.2.0) + actionmailer (= 5.2.0) + actionpack (= 5.2.0) + actionview (= 5.2.0) + activejob (= 5.2.0) + activemodel (= 5.2.0) + activerecord (= 5.2.0) + activestorage (= 5.2.0) + activesupport (= 5.2.0) + bundler (>= 1.3.0) + railties (= 5.2.0) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.4) + loofah (~> 2.2, >= 2.2.2) + railties (5.2.0) + actionpack (= 5.2.0) + activesupport (= 5.2.0) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (12.3.1) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) + sass (3.5.6) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + simple_form (4.0.0) + actionpack (> 4) + activemodel (> 4) + sprockets (3.7.1) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + temple (0.8.0) + thor (0.20.0) + thread_safe (0.3.6) + tilt (2.0.8) + tzinfo (1.2.5) + thread_safe (~> 0.1) + uber (0.1.0) + websocket-driver (0.7.0) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.3) + xpath (3.0.0) + nokogiri (~> 1.8) + +PLATFORMS + ruby + +DEPENDENCIES + capybara_minitest_spec + cells (>= 4.1.6) + cells-erb + cells-rails! + formtastic + minitest-spec-rails + my_engine! + rails (~> 5.2.0) + sass-rails + simple_form + sprockets + +BUNDLED WITH + 1.16.1 diff --git a/test/rails5.2/Rakefile b/test/rails5.2/Rakefile new file mode 100644 index 0000000..ba6b733 --- /dev/null +++ b/test/rails5.2/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Rails.application.load_tasks diff --git a/test/rails5.2/app/assets/images/.keep b/test/rails5.2/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/rails5.2/app/assets/images/logo.jpeg b/test/rails5.2/app/assets/images/logo.jpeg new file mode 100644 index 0000000..7bd23cc Binary files /dev/null and b/test/rails5.2/app/assets/images/logo.jpeg differ diff --git a/test/rails5.2/app/assets/stylesheets/application.css.erb b/test/rails5.2/app/assets/stylesheets/application.css.erb new file mode 100644 index 0000000..75503dc --- /dev/null +++ b/test/rails5.2/app/assets/stylesheets/application.css.erb @@ -0,0 +1,19 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any styles + * defined in the other CSS/SCSS files in this directory. It is generally better to create a new + * file per style scope. + * + *= require_tree . + *= require_self + *= require user + *= require song + */ +<%# capture do %> +<%# end %> \ No newline at end of file diff --git a/test/rails5.2/app/cells/form_for/show.erb b/test/rails5.2/app/cells/form_for/show.erb new file mode 100644 index 0000000..98c427d --- /dev/null +++ b/test/rails5.2/app/cells/form_for/show.erb @@ -0,0 +1,7 @@ +<%= form_for Song.new do |f| %> + First + <%= f.text_field :id %> + <%= f.fields_for :artist do |a| %> + <%= a.text_field :id %> + <% end %> +<% end %> \ No newline at end of file diff --git a/test/rails5.2/app/cells/form_for_cell.rb b/test/rails5.2/app/cells/form_for_cell.rb new file mode 100644 index 0000000..b62f5e9 --- /dev/null +++ b/test/rails5.2/app/cells/form_for_cell.rb @@ -0,0 +1,7 @@ +class FormForCell < Cell::ViewModel + include ActionView::RecordIdentifier + + def show + render + end +end diff --git a/test/rails5.2/app/cells/form_tag/show.erb b/test/rails5.2/app/cells/form_tag/show.erb new file mode 100644 index 0000000..62785ca --- /dev/null +++ b/test/rails5.2/app/cells/form_tag/show.erb @@ -0,0 +1,5 @@ +<%= form_tag songs_path do %> + Second + <%= text_field_tag :id %> + <%= submit_tag "Save" %> +<% end %> diff --git a/test/rails5.2/app/cells/form_tag_cell.rb b/test/rails5.2/app/cells/form_tag_cell.rb new file mode 100644 index 0000000..e8503b0 --- /dev/null +++ b/test/rails5.2/app/cells/form_tag_cell.rb @@ -0,0 +1,5 @@ +class FormTagCell < Cell::ViewModel + def show + render + end +end diff --git a/test/rails5.2/app/cells/formtastic/show.erb b/test/rails5.2/app/cells/formtastic/show.erb new file mode 100644 index 0000000..2c69990 --- /dev/null +++ b/test/rails5.2/app/cells/formtastic/show.erb @@ -0,0 +1,12 @@ +<%= semantic_form_for Song.new do |f| %> + First + <%= f.input :id %> + <%= f.semantic_fields_for :artist do |a| %> + <%= a.input :id %> + <% end %> + + <%= f.actions do %> + <%= f.submit 'Go!', as: :button, class: 'btn btn-primary' %> + <% end %> + +<% end %> \ No newline at end of file diff --git a/test/rails5.2/app/cells/formtastic_cell.rb b/test/rails5.2/app/cells/formtastic_cell.rb new file mode 100644 index 0000000..7e126ae --- /dev/null +++ b/test/rails5.2/app/cells/formtastic_cell.rb @@ -0,0 +1,9 @@ +class FormtasticCell < Cell::ViewModel + include ActionView::RecordIdentifier + include Formtastic::Helpers::FormHelper + include ActionView::Helpers::FormOptionsHelper + + def show + render + end +end diff --git a/test/rails5.2/app/cells/simple_form/show.erb b/test/rails5.2/app/cells/simple_form/show.erb new file mode 100644 index 0000000..d2236f5 --- /dev/null +++ b/test/rails5.2/app/cells/simple_form/show.erb @@ -0,0 +1,7 @@ +<%= simple_form_for Song.new do |f| %> + First + <%= f.input :id %> + <%= f.fields_for :artist do |a| %> + <%= a.input :id %> + <% end %> +<% end %> \ No newline at end of file diff --git a/test/rails5.2/app/cells/simple_form_cell.rb b/test/rails5.2/app/cells/simple_form_cell.rb new file mode 100644 index 0000000..f3c1f3f --- /dev/null +++ b/test/rails5.2/app/cells/simple_form_cell.rb @@ -0,0 +1,11 @@ +class SimpleFormCell < Cell::ViewModel + include ActionView::RecordIdentifier + include SimpleForm::ActionViewExtensions::FormHelper + + # include ActiveSupport::Configurable + # include ActionController::RequestForgeryProtection # FIXME: this does NOT activate any protection. + + def show + render + end +end diff --git a/test/rails5.2/app/cells/song/song.css b/test/rails5.2/app/cells/song/song.css new file mode 100644 index 0000000..da39d11 --- /dev/null +++ b/test/rails5.2/app/cells/song/song.css @@ -0,0 +1 @@ +.song { background: red; } \ No newline at end of file diff --git a/test/rails5.2/app/cells/song/with_escaped.erb b/test/rails5.2/app/cells/song/with_escaped.erb new file mode 100644 index 0000000..8bd1683 --- /dev/null +++ b/test/rails5.2/app/cells/song/with_escaped.erb @@ -0,0 +1 @@ +<%= title %> \ No newline at end of file diff --git a/test/rails5.2/app/cells/song_cell.rb b/test/rails5.2/app/cells/song_cell.rb new file mode 100644 index 0000000..958a6ac --- /dev/null +++ b/test/rails5.2/app/cells/song_cell.rb @@ -0,0 +1,18 @@ +class SongCell < Cell::ViewModel + include Escaped + property :title + + def show + "happy" + end + + def with_escaped + render + end + # include ActionView::Helpers::AssetUrlHelper + # include Sprockets::Rails::Helper + + # self.assets_prefix = Rails.application.config.assets.prefix + # self.assets_environment = Rails.application.assets + # self.digest_assets = Rails.application.config.assets[:digest] +end \ No newline at end of file diff --git a/test/rails5.2/app/controllers/application_controller.rb b/test/rails5.2/app/controllers/application_controller.rb new file mode 100644 index 0000000..d83690e --- /dev/null +++ b/test/rails5.2/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/test/rails5.2/app/controllers/concerns/.keep b/test/rails5.2/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/rails5.2/app/controllers/index_controller.rb b/test/rails5.2/app/controllers/index_controller.rb new file mode 100644 index 0000000..3f52a60 --- /dev/null +++ b/test/rails5.2/app/controllers/index_controller.rb @@ -0,0 +1,7 @@ +class IndexController < ApplicationController + + def index + end + +end + diff --git a/test/rails5.2/app/controllers/musician_controller.rb b/test/rails5.2/app/controllers/musician_controller.rb new file mode 100644 index 0000000..3bca1d5 --- /dev/null +++ b/test/rails5.2/app/controllers/musician_controller.rb @@ -0,0 +1,29 @@ +class MusicianController < ActionController::Base + def view_with_concept_with_show + render inline: %{<%= concept("view_extensions_test/cell", "Up For Breakfast", volume: 1).show %>} # TODO: concept doesn't need .call + end + + def view_with_concept_without_call + render inline: %{<%= concept("view_extensions_test/cell", "A Tale That Wasn't Right") %>} # this tests ViewModel#to_s. + end + + def view_with_concept_with_call + render inline: %{<%= concept("view_extensions_test/cell", "A Tale That Wasn't Right").call %>} + end + + def view_with_cell_with_call + render inline: %{<%= cell("view_extensions_test/song", "A Tale That Wasn't Right").call %>} + end + + def view_with_collection_without_call + render inline: %{<%= cell("view_extensions_test/song", collection: ["A Tale That Wasn't Right"]) %>} + end + + def action_with_concept_with_call + render plain: concept("view_extensions_test/cell", "A Tale That Wasn't Right").call + end + + def action_with_cell_with_call + render plain: cell("view_extensions_test/song", "A Tale That Wasn't Right").call + end +end diff --git a/test/rails5.2/app/controllers/songs_controller.rb b/test/rails5.2/app/controllers/songs_controller.rb new file mode 100644 index 0000000..326ca9b --- /dev/null +++ b/test/rails5.2/app/controllers/songs_controller.rb @@ -0,0 +1,32 @@ +class SongsController < ApplicationController + def show + # renders show.html.haml + end + + def index + render plain: cell(:song).() + end + + def new + render plain: cell(:song).url_for(Song.new) + end + + def edit + render plain: cell(:song).video_path(1) + end + + def with + method = params[:song][:method] + args = params[:song][:args] + + render plain: cell("songs_controller/asset").send(method, args) + end + + def with_escaped + render layout: false + end + + require "cell/helper/asset_helper" + class AssetCell < Cell::ViewModel + end +end diff --git a/test/rails5.2/app/helpers/application_helper.rb b/test/rails5.2/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/test/rails5.2/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/test/rails5.2/app/mailers/.keep b/test/rails5.2/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/rails5.2/app/models/.keep b/test/rails5.2/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/rails5.2/app/models/artist.rb b/test/rails5.2/app/models/artist.rb new file mode 100644 index 0000000..2a53e6a --- /dev/null +++ b/test/rails5.2/app/models/artist.rb @@ -0,0 +1,25 @@ +class Artist + require "active_model" + include ActiveModel::Conversion + include ActiveModel::Naming + + def persisted? + true + end + + def parents + [] + end + + def name + "artist" + end + + def id + 1 + end + + # def artist + # Artist.new + # end +end diff --git a/test/rails5.2/app/models/concerns/.keep b/test/rails5.2/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/rails5.2/app/models/song.rb b/test/rails5.2/app/models/song.rb new file mode 100644 index 0000000..93a2a58 --- /dev/null +++ b/test/rails5.2/app/models/song.rb @@ -0,0 +1,25 @@ +class Song < OpenStruct + require "active_model" + include ActiveModel::Conversion + extend ActiveModel::Naming + + def persisted? + true + end + + def parents + [] + end + + def name + "song" + end + + def id + 1 + end + + def artist + Artist.new + end +end diff --git a/test/rails5.2/app/views/index/index.html.erb b/test/rails5.2/app/views/index/index.html.erb new file mode 100644 index 0000000..aeabffc --- /dev/null +++ b/test/rails5.2/app/views/index/index.html.erb @@ -0,0 +1,6 @@ +

Hello World

+<%= link_to "render", my_engine.user_path %> + + +hello? +<%= concept( "user/cell") %> \ No newline at end of file diff --git a/test/rails5.2/app/views/layouts/application.html.erb b/test/rails5.2/app/views/layouts/application.html.erb new file mode 100644 index 0000000..0a6d69e --- /dev/null +++ b/test/rails5.2/app/views/layouts/application.html.erb @@ -0,0 +1,13 @@ + + + + EngineCells + <%= stylesheet_link_tag 'application', media: 'all' %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/test/rails5.2/app/views/songs/show.html.erb b/test/rails5.2/app/views/songs/show.html.erb new file mode 100644 index 0000000..cc2fe20 --- /dev/null +++ b/test/rails5.2/app/views/songs/show.html.erb @@ -0,0 +1 @@ +<%= cell(:form_for) %> \ No newline at end of file diff --git a/test/rails5.2/app/views/songs/with_escaped.html.erb b/test/rails5.2/app/views/songs/with_escaped.html.erb new file mode 100644 index 0000000..c32345c --- /dev/null +++ b/test/rails5.2/app/views/songs/with_escaped.html.erb @@ -0,0 +1 @@ +

Yeah!

<%= cell(:song, Song.new(title: "" + end + + it do + get :with, params: { song: { method: :stylesheet_link_tag, args: "application" } } + response.body.must_equal "" + end + + it do + get :with, params: { song: { method: :asset_url, args: "application.css" } } + response.body.must_equal "http://assets.com/assets/application.css" + end +end diff --git a/test/rails5.2/test/integration/asset_pipeline_test.rb b/test/rails5.2/test/integration/asset_pipeline_test.rb new file mode 100644 index 0000000..93b7c92 --- /dev/null +++ b/test/rails5.2/test/integration/asset_pipeline_test.rb @@ -0,0 +1,17 @@ +require "test_helper" +require "capybara/rails" +require "capybara/dsl" + +# This blog post helped so much: http://rakeroutes.com/blog/write-a-gem-for-the-rails-asset-pipeline/ +# Thanks, Stephen!!! :) + +class AssetPipelineTest < ActionDispatch::IntegrationTest + include ::Capybara::DSL + + it do + visit "/assets/application.css" + + # both engine User::Cell and SongCell provide assets. + page.text.must_include "user { background: green; } .song { background: red; }" + end +end diff --git a/test/rails5.2/test/integration/controller_test.rb b/test/rails5.2/test/integration/controller_test.rb new file mode 100644 index 0000000..657679c --- /dev/null +++ b/test/rails5.2/test/integration/controller_test.rb @@ -0,0 +1,16 @@ +require "test_helper" + +class ControllerTest < ActionController::TestCase + tests SongsController + + it do + get :index + response.body.must_equal "happy" + end + + # HTML escaping. + it do + get :with_escaped + response.body.must_equal "

Yeah!

<script>" # only the property is escaped. + end +end \ No newline at end of file diff --git a/test/rails5.2/test/integration/form_for_test.rb b/test/rails5.2/test/integration/form_for_test.rb new file mode 100644 index 0000000..cb0fdb0 --- /dev/null +++ b/test/rails5.2/test/integration/form_for_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +class FormForTestTest < MiniTest::Spec + include Cell::Testing + + it do + cell("form_for").().gsub(/\s\s/, "").must_equal %{
First
} + end +end \ No newline at end of file diff --git a/test/rails5.2/test/integration/form_tag_test.rb b/test/rails5.2/test/integration/form_tag_test.rb new file mode 100644 index 0000000..88da0d9 --- /dev/null +++ b/test/rails5.2/test/integration/form_tag_test.rb @@ -0,0 +1,10 @@ +require "test_helper" + +class FormTagTestTest < MiniTest::Spec + include Cell::Testing + controller SongsController + + it do + cell("form_tag").().gsub(/\s\s/, "").must_equal %{
Second
} + end +end diff --git a/test/rails5.2/test/integration/formtastic_test.rb b/test/rails5.2/test/integration/formtastic_test.rb new file mode 100644 index 0000000..0c39589 --- /dev/null +++ b/test/rails5.2/test/integration/formtastic_test.rb @@ -0,0 +1,10 @@ +require "test_helper" + +class FormForTestTest < MiniTest::Spec + include Cell::Testing + controller SongsController # provides #url_options. + + it do + cell("formtastic").().gsub(/\s\s/, "").must_equal %{
First
    } + end +end diff --git a/test/rails5.2/test/integration/simple_form_test.rb b/test/rails5.2/test/integration/simple_form_test.rb new file mode 100644 index 0000000..f8c2711 --- /dev/null +++ b/test/rails5.2/test/integration/simple_form_test.rb @@ -0,0 +1,10 @@ +require "test_helper" + +class SimpleFormTest < MiniTest::Spec + include Cell::Testing + controller SongsController # provides #url_options. + + it do + cell("simple_form").().gsub(/\s\s/, "").must_equal %{
    First
    } + end +end diff --git a/test/rails5.2/test/integration/url_helper_test.rb b/test/rails5.2/test/integration/url_helper_test.rb new file mode 100644 index 0000000..c2ca59b --- /dev/null +++ b/test/rails5.2/test/integration/url_helper_test.rb @@ -0,0 +1,52 @@ +require 'test_helper' + +class MusiciansController < ApplicationController +end + +class WithDefaultOptionsController < ApplicationController + private + def default_url_options(options={}) + options.merge(anchor: 'foobar') + end +end + +class UrlCell < Cell::ViewModel + def show + url_for(model) + end +end + +class UrlHelperTest < MiniTest::Spec + include Cell::Testing + controller MusiciansController + + let (:song_cell) { UrlCell.new(Song.new, context: { controller: controller }) } + + # path helpers work in cell instance. + it { song_cell.songs_path.must_equal "/songs" } + it { song_cell.().must_equal "http://test.host/songs/1" } +end + + +class UrlTest < ActionDispatch::IntegrationTest + include ::Capybara::DSL + + it do + visit "/songs/new" # cell.url_for(Song.new) + page.text.must_equal "http://www.example.com/songs/1" + end + + # it do + # visit "/songs/1/edit" + # page.text.must_equal "http://www.example.com/songs/1" + # end +end + +class DefaultOptionsTest < MiniTest::Spec + include Cell::Testing + controller WithDefaultOptionsController + + let (:song_cell) { UrlCell.new(Song.new, context: { controller: controller }) } + + it { song_cell.songs_path.must_equal "/songs#foobar" } +end diff --git a/test/rails5.2/test/public_test.rb b/test/rails5.2/test/public_test.rb new file mode 100644 index 0000000..842d0e8 --- /dev/null +++ b/test/rails5.2/test/public_test.rb @@ -0,0 +1,12 @@ +require "test_helper" + +class PublicTest < MiniTest::Spec + # ::rails_version + it { Cell.rails_version.must_equal Gem::Version.new(ActionPack::VERSION::STRING) } + + # ViewModel.cell(collection: []) renders html_safe. + it { Cell::ViewModel.cell("song", collection: [Object]).().class.must_equal ActiveSupport::SafeBuffer } + + # #call returns html_safe. + it { SongCell.new(nil).().must_be_instance_of ActiveSupport::SafeBuffer } +end diff --git a/test/rails5.2/test/rails_extensions_test.rb b/test/rails5.2/test/rails_extensions_test.rb new file mode 100644 index 0000000..a18e172 --- /dev/null +++ b/test/rails5.2/test/rails_extensions_test.rb @@ -0,0 +1,56 @@ +require 'test_helper' + +class ViewExtensionsTest < ActionController::TestCase + tests MusicianController + + class Cell < Cell::Concept + def show + "#{model}" + end + end + + class SongCell < ::Cell::ViewModel + def show + "#{model}" + end + end + + + # #concept is available in controller views. + test "concept(..).show" do + get :view_with_concept_with_show + assert_equal "<b>Up For Breakfast</b>", @response.body # TODO: test options/with twin. + end + + test "concept(..).call" do + get :view_with_concept_with_call + assert_equal "A Tale That Wasn't Right", @response.body # TODO: test options/with twin. + end + + test "concept(..) without #call" do + get :view_with_concept_without_call + assert_equal "A Tale That Wasn't Right", @response.body + end + + test "cell(collection: ..) without #call" do + get :view_with_collection_without_call + assert_equal "A Tale That Wasn't Right", @response.body + end + + test "cell(..) with #call" do + get :view_with_cell_with_call + assert_equal "A Tale That Wasn't Right", @response.body + end + + # Controller#concept + test "Controller#concept(..).call" do + get :action_with_concept_with_call + assert_equal "A Tale That Wasn't Right", @response.body # TODO: test options/with twin. + end + + # Controller#cell + test "Controller#cell(..).call" do + get :action_with_cell_with_call + assert_equal "A Tale That Wasn't Right", @response.body # TODO: test options/with twin. + end +end diff --git a/test/rails5.2/test/test_helper.rb b/test/rails5.2/test/test_helper.rb new file mode 100644 index 0000000..2ee19f7 --- /dev/null +++ b/test/rails5.2/test/test_helper.rb @@ -0,0 +1,44 @@ +ENV['RAILS_ENV'] = 'test' +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +# MiniTest::Spec.class_eval do +# after :each do +# # DatabaseCleaner.clean +# Thing.delete_all +# Comment.delete_all +# User.delete_all +# end +# end + +class MusicianController < ActionController::Base + def view_with_concept_with_show + render inline: %{<%= concept("view_extensions_test/cell", "Up For Breakfast", volume: 1).show %>} # TODO: concept doesn't need .call + end + + def view_with_concept_without_call + render inline: %{<%= concept("view_extensions_test/cell", "A Tale That Wasn't Right") %>} # this tests ViewModel#to_s. + end + + def view_with_concept_with_call + render inline: %{<%= concept("view_extensions_test/cell", "A Tale That Wasn't Right").call %>} + end + + def view_with_cell_with_call + render inline: %{<%= cell("view_extensions_test/song", "A Tale That Wasn't Right").call %>} + end + + def view_with_collection_without_call + render inline: %{<%= cell("view_extensions_test/song", collection: ["A Tale That Wasn't Right"]) %>} + end + + def action_with_concept_with_call + render plain: concept("view_extensions_test/cell", "A Tale That Wasn't Right").call + end + + def action_with_cell_with_call + render plain: cell("view_extensions_test/song", "A Tale That Wasn't Right").call + end +end + +Rails.backtrace_cleaner.remove_silencers! # YES, stacktraces are awesome! diff --git a/test/rails5.2/test/translation_test.rb b/test/rails5.2/test/translation_test.rb new file mode 100644 index 0000000..ad1ee33 --- /dev/null +++ b/test/rails5.2/test/translation_test.rb @@ -0,0 +1,45 @@ +require "test_helper" +require "cell/translation" + +class TranslationTest < MiniTest::Spec + class I18nCell < Cell::ViewModel + include ActionView::Helpers::TranslationHelper + include Cell::Translation + + def greet_relative + t(".greeting") # gets appended to translation_test.i18n. + end + + def greet_absolute + t("translation_test.i18n.greeting") + end + end + + I18n.backend = I18n::Backend::KeyValue.new({}) + I18n.backend.store_translations(:en, + { "translation_test.i18n.greeting" => "Translated!", + "cell.friendly.greeting" => "Hello you!" }, + escape: false) + + # Translate text specified by an absolute path + it { I18nCell.new.greet_absolute.must_equal "Translated!" } + + # Translate text specified by an relative path + it { I18nCell.new.greet_relative.must_equal "Translated!" } + + + describe "::translation_path" do + class ExplicitI18NCell < Cell::ViewModel + include ActionView::Helpers::TranslationHelper + include Cell::Translation + + self.translation_path = "cell.friendly" + + def show + t(".greeting") + end + end + + it { ExplicitI18NCell.new.().must_equal "Hello you!" } + end +end