This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'capybara/rails' | |
| require 'capybara/rspec' | |
| require 'rack/handler/puma' | |
| require 'selenium/webdriver' | |
| # Default cache time of 24 hours before webdrivers checks for new versions | |
| Webdrivers.cache_time = 24.hours.to_i | |
| # Logging levels are :info (more verbosity), :warn (default), :error, etc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sample_pdf_upload | |
| sample_path = Rails.root.join("spec/fixtures/sample_file.pdf") | |
| #fixture_file_upload(sample_path, 'application/pdf') ### MINITEST | |
| Rack::Test::UploadedFile.new(sample_path) ### RSPEC | |
| end | |
| def sample_csv_upload | |
| sample_path = Rails.root.join("spec/fixtures/sample_file.csv") | |
| #fixture_file_upload(sample_path, 'text/csv') ### MINITEST | |
| Rack::Test::UploadedFile.new(sample_path) ### RSPEC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DATE_FORMAT = "%F".freeze ### Rails default is "%m/%d/%Y" | |
| TIME_FORMAT = "#{DATE_FORMAT} %l:%M%p %Z".freeze | |
| format_defaults = { | |
| date_time12: TIME_FORMAT, | |
| date_time24: "#{DATE_FORMAT} %H:%M %Z".freeze, | |
| }.freeze | |
| Date::DATE_FORMATS.merge!(format_defaults.merge({default: DATE_FORMAT})) | |
| Time::DATE_FORMATS.merge!(format_defaults.merge({default: TIME_FORMAT})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| ### USAGE: `./convert_slim_to_erb path/to/views/` | |
| ### LIMITATIONS: | |
| ### - Does not add closing tags such as `<% end %>` or `</div>` | |
| SELF_CLOSING_TAGS = ["input","br","hr","img","meta","area","base","col","embed","link","source","track","wbr","param"].freeze | |
| @line = nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### Article about the BOM: https://estl.tech/of-ruby-and-hidden-csv-characters-ef482c679b35 | |
| ### Article about other CSV gotchas: https://blog.rubyhero.dev/solving-problems-with-csv-parsing | |
| ### Remove Blank Rows from end of file | |
| ### Ideally this would be handled by the controller to sanitize before saving upload however I wasnt able to make that work | |
| file_data = file.read.sub(/[,\n\r\t ]*\z/, "") | |
| i = -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # lib/<project_name>/engine.rb | |
| module RailsI18nManager | |
| class Engine < ::Rails::Engine | |
| isolate_namespace RailsI18nManager | |
| ### Automatically load all migrations into main rails app | |
| initializer "rails_i18n_manager.append_migrations" do |app| | |
| if !app.root.to_s.match?(root.to_s) | |
| config.paths["db/migrate"].expanded.each do |expanded_path| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # lib/<project_name>/engine.rb | |
| module RailsI18nManager | |
| class Engine < ::Rails::Engine | |
| isolate_namespace RailsI18nManager | |
| initializer "rails_i18n_manager.load_static_assets" do |app| | |
| ### Expose static assets | |
| app.middleware.use ::ActionDispatch::Static, "#{root}/public" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def self.with_fresh_i18n_load_paths(load_paths, &block) | |
| prev_load_path = I18n.load_path | |
| I18n.load_path = load_paths | |
| I18n.backend.reload! | |
| block.call | |
| ensure | |
| I18n.load_path = prev_load_path | |
| I18n.backend.reload! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### BUNDLER | |
| require "bundler/inline" | |
| gemfile(true) do | |
| source "https://rubygems.org" | |
| ruby '2.4.1' | |
| gem "rails" | |
| gem "sqlite3" | |
| #gem 'responders' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%= form_for @post do |f| %> | |
| <div class="comments-wrapper"> | |
| <% f.fields_for :comments do |f2| %> | |
| <%= render "comment_fields", f: f2 %> | |
| <% end %> | |
| </div> | |
| <button type="button" class="add-comment">Add Comment</button> | |
| <script> |