How to write tests for email views in Rails? - ruby-on-rails

In ActiveAdmin I have setup a small form for sending bulk emails to users. In the form I have the option to parse text using html or markdown. I have two different views and depending on the content type attribute of the email, one of the two is rendered. I pass the #content of the email to the views and in the one I call simple_format #content and in the other - a helper method markdown #content. So the question is - how do I test the email views. Everywhere I see ways to preview emails in the browser, but I want to have some written tests, which I can run along with my full test suit. So far, the only idea I have come up with is to use Capybara and something like:
visit '/mail_view'
expect(find 'a.reset_password').to contain reset_password_path(user)
Is this the way to go or is there another standard?

Related

Mailboxer html formattting

How can I allow Mailboxer gem to send HTML formatted messages?
For example, I want the first message user A sends to user B to be pre-formatted with certain text and HTML tags. Currently any kind of markup is escaped..
EDIT: My question is basically how can I "patch" the send_message functionality? Or create a new send_message2 that behaves the way I want?

What does the term "template" mean?

I am learning Rails 5.0, via a tutorial. Learning how to generate view templates, but the term "template" is never explicitly defined. I've searched in the Rails docs, and they seem to mention the word a lot, but also never really define it explicitly.
I know that views are the HTML, CSS associated with what the user sees. But was wondering what is a template and how is it different than a standard webpage?
I don't have an authoritative answer. But this is really rather simple. RoR lets you generate content dynamically. This means, with one template, you could generate different content (html pages). The final html page generated and served by the server is the webpage endusers see. For example, you could have a template show.html.erb with the following line:
<h> Product <%=#product.name%> </h>
From this template, different webpages for each different #product can be generated with that #product's name, depending on the #product variable, which is provided by the controller.
So templates allow you to dynamically generate content and render them as different html webpages.

How to allow users to edit dynamic slim page templates in production for rails 4?

Essentially I'm trying to implement a way so that users can edit slim that is stored in the database.
For example they would use the form to create a new page and insert the html for that page in a text field which would be saved in the database. I want to allow them to edit that page in slim. By the way the html stored is slim not plain html.
If I store slim in the database how do I get rails to render the html properly on the client side in production? So in other words would rails automatically do this since the view is being render like so:
views/page/view.html.slim
page.header
page.content
page.footer
or would I have to figure out a way to convert on the fly? I might be making this more complicated then I should but I'm new to this
If I understand you correctly you want to convert the slim to Html and output that in your views.
This is directly from slims doc. This is how it processes slim files and outputs it.
Tilt.new['template.slim'].render(scope)
Slim::Template.new('template.slim', optional_option_hash).render(scope)
Slim::Template.new(optional_option_hash) { source }.render(scope)
so in short
Slim::Template.new(page/view.html.slim).render
put that in a module to make it prettier and I think you're good. You may want to use rails path helper to get the direct link for the view. You may also want to consider figuring out a way to catch the errors in indentation so that your output doesn't bug out in production. Some kind of validation that prevents it from saving if not properly formatted should help.

How to edit a model instance's text field (storing HTML) using markup/down editor?

(app is built on Rails 4.0.3/postgres)
I have a model defined where one of the attributes is a text field containing the entire HTML of a webpage- I store it as text, which I then set as an instance variable (#html) in the controller and then render it through a view using <%=raw #html %>. This allows me to store and render entire pages easily.
My question is, I need to allow users to edit the HTML in-browser using some kind of markup language/editor, so how would I go about doing so? The workflow would be that the user clicks on an instance of the model through a dashboard, and then is able to edit the name of model instance (easy), and under that is able to edit the html attribute and save it via some kind of markup editor like Github's gist editor. I feel like this should be easy but can't figure it out- can anyone point me in the right direction?
Thanks!

laravel 4 - how to include an editor into Laravel 4

I have an application in Laravel 4 to manage newsletter.
It the back end is possible to write the message that will be sent as email to the users in the list.
There is a simple form with two fiels: subject - body
The point is that i can send only plain text.
It is possible to include an editor with some basics functions: bold - italic - color - size - headings?
Thank you.
That wouldn't be part of the back end but would be done with javascript. What you are probably looking for is something like CKEditor which basically hijacks <textarea> elements on your page and turns them into almost full featured editors.
How it works is it automatically inserts appropriate HTML tags into the text as it's typed depending on how the user wants it to look. When the form is submitted, instead of plain text, it would be submitted as the generated HTML, and you'd probably just want to drop that into the body of the email.
Check out http://www.ckeditor.com
If you have any specific questions on that, I'd be sure to add the appropriate tags so you have a better chance of getting help on it.

Resources