-
Notifications
You must be signed in to change notification settings - Fork 0
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
send_mail_to_users #6
Changes from 21 commits
a11af46
6369f1b
585f69a
a36834f
f75a164
c8dc2f7
1bd88c6
57caaff
c0ca374
c58c404
cfa7197
e02558e
a42d56e
6bf6bdf
a4b86f4
a2d9832
73c2d95
9d7fbe1
cc8d323
6a83e9b
adabf26
b3976fa
9af5bcb
b83a9e2
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 |
---|---|---|
@@ -1 +1 @@ | ||
<%= JsRoutes.generate(default_url_options: {:host => ENV['APP_DOMAIN']}, url_links: true, exclude: [/admin/] ) %> | ||
<%= JsRoutes.generate(default_url_options: { :host => 'localhost:3000' }, url_links: true, exclude: [/admin/] ) %> | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
class Api::V1::ErrorsController < Api::V1::ApiController | ||
skip_before_action :authenticate_member! | ||
skip_before_action :authenticate_member!, except: [:index, :show, :update, :notify_subscribers] | ||
|
||
def index | ||
@errors = current_site.issues | ||
end | ||
|
||
def create | ||
# binding.pry | ||
end | ||
|
||
def show | ||
@error = current_site.issues.where('issues.id = ?', params[:id]).first | ||
end | ||
|
||
def update | ||
@error = Issue.find(params[:id]) | ||
@error.update_attributes(error_params) | ||
end | ||
|
||
def notify_subscribers | ||
@error = Issue.find(params[:id]) | ||
@message = params[:message] | ||
@error.subscribers.each do |member| | ||
UserMailer.issue_solved(@error, member, @message).deliver_now | ||
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. Hai sa schimbam si numele asta sa ii zicem 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. Deci fai |
||
end | ||
end | ||
|
||
|
||
private | ||
def error_params | ||
params.require(:error).permit(:status) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ class ErrorsController < ApplicationController | |
def index | ||
end | ||
|
||
def show | ||
def show | ||
gon.error_id = params[:id] | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
class InstallationsController < ApplicationController | ||
def index | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class ApplicationMailer < ActionMailer::Base | ||
default from: "[email protected]" | ||
layout 'mailer' | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class UserMailer < ApplicationMailer | ||
|
||
def issue_solved(issue, subscriber, message) | ||
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. notify_subscriber ar trebuii sa fie numele la metoda asta pentru ca o sa dam voie ownerilor sa dea mesaje subscriberilor de mai multe ori. Normal ca trebuie sa schimbi si specurile si controlleru. |
||
@issue = issue | ||
@message = message | ||
@website = Website.find(@issue.website_id) | ||
@member = subscriber | ||
mail(to: @member.email, subject: 'Subscriber notification') | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.error(@error, :id) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.error(@error, :status) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
%hmtl | ||
%body | ||
= yield |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
= yield |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Welcome, #{@member.name} | ||
%p An issue has just been solved. | ||
%p Website title: #{@website.title} | ||
%p #{@message} | ||
%p Thanks for joining and have a great day! | ||
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. Schimba mailu asta sa fie asa:
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
REDIS0006�ܳC�Z��V |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
require 'rails_helper' | ||
include Devise::TestHelpers | ||
|
||
|
||
describe Api::V1::ErrorsController, :type => :controller do | ||
let(:member) { create :member } | ||
let(:website) { create :website, member: member } | ||
let(:issue_error) { create :issue, website: website } | ||
let(:subscriber) { create :subscriber, website: website } | ||
let!(:issue_subscriber) { create :subscriber_issue, issue: issue_error, subscriber: subscriber } | ||
let(:message) { 'asdada' } | ||
|
||
describe 'POST #notify_subscribers' do | ||
before { auth_member(member) } | ||
|
||
it 'should email subscribers' do | ||
mailer = double('UserMailer') | ||
expect(mailer).to receive(:deliver_now) | ||
expect(UserMailer).to receive(:issue_solved).with(issue_error, subscriber, message).and_return(mailer).once | ||
|
||
post :notify_subscribers, { message: message, id: issue_error.id, format: :json } | ||
end | ||
|
||
it 'should email 2 subscribers' do | ||
subscriber2 = create :subscriber, website: website | ||
subscriber_issue = create :subscriber_issue, issue: issue_error, subscriber: subscriber2 | ||
mailer = double('UserMailer') | ||
expect(mailer).to receive(:deliver_now).twice | ||
expect(UserMailer).to receive(:issue_solved).with(issue_error, an_instance_of(Subscriber), message).and_return(mailer).twice | ||
post :notify_subscribers, { message: message, id: issue_error.id, format: :json } | ||
end | ||
|
||
it 'should assign error' do | ||
post :notify_subscribers, { id: issue_error.id, error: {status: issue_error.status }, format: :json } | ||
expect(assigns(:error)).to eq(issue_error) | ||
end | ||
|
||
it 'should assign message' do | ||
post :notify_subscribers, { message: 'asdada', id: issue_error.id, format: :json } | ||
expect(assigns(:message)).to eq('asdada') | ||
end | ||
end | ||
|
||
describe 'GET #index' do | ||
it 'should assign current_site errors' do | ||
auth_member(member) | ||
get :index, { website_id: website.id, format: :json} | ||
expect(assigns(:errors)).to eq([issue_error]) | ||
end | ||
|
||
it 'should give error if not logged in' do | ||
get :index, { website_id: website.id, format: :json} | ||
expect(response.body).to eq({errors: ['Authorized users only.']}.to_json) | ||
expect(response).to have_http_status(401) | ||
end | ||
|
||
it 'should render json' do | ||
auth_member(member) | ||
get :index, { website_id: website.id, format: :json} | ||
expect(response).to be_successful | ||
expect(response.content_type).to eq('application/json') | ||
end | ||
end | ||
|
||
describe 'GET #show' do | ||
it 'should assign error' do | ||
auth_member(member) | ||
get :show, { id: issue_error.id, error: {status: issue_error.status }, website_id: website.id, format: :json } | ||
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. aici nu ai nevoie de |
||
expect(assigns(:error)).to eq(issue_error) | ||
end | ||
|
||
it 'should render json' do | ||
auth_member(member) | ||
get :show, { id: issue_error.id, error: {status: issue_error.status }, website_id: website.id, format: :json } | ||
expect(response).to be_successful | ||
expect(response.content_type).to eq('application/json') | ||
end | ||
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. adauga un test la fel ca ala de la index fara auth_member. Codu tre sa fie exact la fel doar ca faci get :show in loc de get :index si ma rog cu id. |
||
end | ||
|
||
describe 'PUT #update' do | ||
it 'should assign error' do | ||
auth_member(member) | ||
put :update, { id: issue_error.id, error: {status: issue_error.status }, format: :json } | ||
expect(assigns(:error)).to eq(issue_error) | ||
end | ||
|
||
it 'should update error status' do | ||
auth_member(member) | ||
expect { | ||
put :update, { id: issue_error.id, error: { status: "resolved" }, website_id: website.id, format: :json} | ||
issue_error.reload | ||
}.to change(issue_error, :status).from('unresolved').to('resolved') | ||
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. aici ai un spatiu in fata la linia asta }.to tre sa fie pe verticala la fel ca expect |
||
end | ||
|
||
it 'should not allow update of other parameters other than status' do | ||
auth_member(member) | ||
expect{ put :update, { id: issue_error.id, error: { error: issue_error.status }, website: website.id, format: :json }}.to_not change(issue_error, :status).from("unresolved") | ||
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. aici te rog sa identezi cum trebuie linia asta. |
||
end | ||
|
||
it 'should render json' do | ||
auth_member(member) | ||
put :update, { id: issue_error.id, error: { status: issue_error.status }, format: :json } | ||
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. aici schimba |
||
expect(response).to be_successful | ||
expect(response.content_type).to eq('application/json') | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
FactoryGirl.define do | ||
factory :issue do | ||
page_title "Homepage" | ||
description "test description for error" | ||
association :website | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
FactoryGirl.define do | ||
factory :subscriber do | ||
name "Test User 1" | ||
email "testuser@google.com" | ||
name Faker::Name.name | ||
sequence(:email) { |n| "person#{n}@example.com" } | ||
association :website | ||
|
||
issues {[FactoryGirl.create(:issue)]} | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer | ||
class UserMailerPreview < ActionMailer::Preview | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe UserMailer, type: :mailer do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
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.
asta nu a mers sa lasi cu ENV?? De ce ai pus fix localhost:3000 ??
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.
te rog sa pui la loc ENV['APP_DOMAIN'] aici si o sa fac merge.