I have problem in Salesforce.com Streaming API using CookieJar.
"CookieJar::InvalidCookieError: Domain is inappropriate based on request URI hostname"
It seem that Salesforce is setting the cookie domain as ".salesforce.com" which will not match the corresponding request domain according to RFC 2109.
Can any one help me?
Just add below to gemfile.
gem 'restforce', '~> 2.2', '>= 2.2.1'
gem 'faye', '0.8.9'
gem "cookiejar", :git => "https://github.com/MissionCapital/cookiejar.git"
Now create an initializer rest_for as below.
require 'faye'
Restforce.configure do |config|
config.username = ENV['SALESFORCE_USERNAME']
config.password = ENV['SALESFORCE_PASSWORD']
config.client_id = ENV['SALESFORCE_CLIENT_ID']
config.client_secret = ENV['SALESFORCE_CLIENT_SECRET']
config.host = ENV['SALESFORCE_HOST'] if ENV['SALESFORCE_HOST'].present?
config.instance_url = ENV['SALESFORCE_INSTANCE_URL'] if ENV['SALESFORCE_INSTANCE_URL'].present?
end
client = Restforce.new
credentials = client.authenticate!
Thread.abort_on_exception = true
Thread.new {
EM.run {
# Subscribe to the PushTopic.
client.subscribe 'YOUR_CHANNEL_NAME' do |message|
p message.inspect
end
}
}
Just remember to use proper host for development and production. In development use test.salesforce.com.
Hope this help someone who facing the same issue.
Related
I'm using mailgun with ActionMailer like this:
config.action_mailer.delivery_method = :mailgun
config.action_mailer.mailgun_settings = {
api_key: 'key-b46eXXXXXXXXXXXX91c4',
domain: 'mg.eagle.com'
}
Mails go out like this:
mail(to: #contact, subject: 'Ask a Question', reply_to: #email, from: #email)
How can I add tags to my mails? There is an example in the mailgun documentation (https://documentation.mailgun.com/en/latest/user_manual.html#tagging) but that doesn't use ActionMailer but a POST on the API...
I found the solution to this, it's actually pretty simple:
Put the following line before the mail command:
headers['X-Mailgun-Tag'] = 'contact_us'
However this will only work if the Pull request is merged:
https://github.com/mailgun/mailgun-ruby/pull/133
Until then you can use this in the Gemfile:
gem 'mailgun-ruby', :github => 'mailgun/mailgun-ruby', :branch => 'sjohn/railgun-mailer-headers'
I am working on a project where I generate and store pdf in the database using apex_util.get_print_document.
It looks like this,
begin
l_report := apex_util.get_print_document (
p_application_id => :APP_ID,
p_report_query_name => 'query_name',
p_report_layout_name => 'layout_name',
p_report_layout_type => 'xsl-fo',
p_document_format => 'pdf' );
Update table_blob
Set report = l_report,
mimetype = 'application/pdf',
filename = :P1_INVOICE_NO||'.pdf',
report_saved_by = :USER,
report_saved_on = sysdate
Where Job_id = :P1_JOB;
End;
This works perfectly in http connection. So when I access the same page over https I am getting the below error. Please help!
ORA-20001: The printing engine could not be reached because either the URL specified is incorrect or a proxy URL needs to be specified.
For APEX to be able to make outbound HTTP calls over SSL, a database wallet must be created and the configuration of it must be specified in APEX Instance Administration:
http://docs.oracle.com/cd/E59726_01/doc.50/e39151/adm_wrkspc002.htm#sthref384
I have a rails (4.1) app running on Heroku with cloudflare as the CDN. In the error logs from NewRelic I see a constant trickle of requests for expired css and js assets, primarily application-<fingerprint>.js and application-<fingerprint>.css(with fingerprints that have been expired).
I am wondering about a solution to redirect these requests to the current asset but I am uncertain if this is a good/safe thing to do.
In my routes I'd add
get "assets/:asset_name" => "assets#show"
and then add an assets_controller.rb with:
class AssetsController < ApplicationController
skip_before_action :authenticate_user!
skip_before_action :verify_authenticity_token, :only => [:show]
def show
begin
asset_name = params[:asset_name].gsub(/-[0-9a-f]{32}$/, "") << ".#{params[:format]}"
if ["css", "js"].include?(params[:format])
redirect_to "/assets/" + Rails.application.assets.find_asset(asset_name).digest_path
else
return asset_not_found!
end
rescue
return asset_not_found!
end
end
private
def asset_not_found!
render :text => "asset #{params[:asset_name]}.#{params[:format]} not found", :status => 404
end
end
I've tried this out on a stage environment and it works but I'm not sure if this is the right way.
In particular the need to have skip_before_action :verify_authenticity_token bothers me, but without it requests for .js assets result in a InvalidCrossOriginRequest error.
I only see requests for expired css and js assets, not for any image assets, hence the above check for the request format being either "css" or "js", but maybe that's an unnecessary step.
So my question is; would doing this be bad practice? Is there a better way to handle requests for expired assets?
i consider this a bad practice.
not particular the way that you implemented id (even though i think there are better ways using rack middlewares), but more because of the fact that you should not redirect those expired assets anywhere.
if a user requests a css or js file with a stale fingerprint they likely have a html document that is out of date and you will probably want him to reload what he has: "there is a new version, please reload your site".
deploying is taken care of at heroku since sprockets stores up to 3 versions of the assets for you https://devcenter.heroku.com/articles/rails-4-asset-pipeline#only-generate-digest-assets
I am trying to test my rails app using cucumber and webrat. I'm trying to get the test to login as a user who is already created and stored in the database, and I'm getting the following error:
Then I see a login error message # features/step_definitions/user_steps.rb:16
expected the following element's content to include "Welcome admin":
Csa
Welcome Guest
Forgot password?
or
Register
HomeJobs
English
Cymraeg
Welcome to CS-Alumni News
The is where the home page text will go.
(RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/user_steps.rb:18:in `/^I see a login error message$/'
features/users/login.feature:9:in `Then I see a login error message'
I changed the code to get it to login a user instead of failing to log in a user due to invalid details, as that wasn't working, and I wasn't sure if it was because it didn't pick up the flash message or not.
Here is the step_definitions file (user_steps.rb)
require 'webrat'
Given /^I do not have an account$/ do
#user = FactoryGirl.create(:user)
#user ||= User.where(:email >= #user[:email]).first
#user.destroy unless #user.nil?
end
When /^I attempt to login with my details$/ do
visit new_session_path
fill_in "login-input", :with => "admin"
fill_in "password", :with => "taliesin"
clicks_button "Login"
end
Then /^I see a login error message$/ do
visit home_path
response.should contain("Welcome admin")
end
And /^I should not be logged in$/ do
#response.should_not contain("Welcome admin")
end
Here is the login.feature file:
Feature: Login
In order to access my account
As a user
I want to be able to login
Scenario: User does not have an account
Given I do not have an account
When I attempt to login with my details
Then I see a login error message
And I should not be logged in
Scenario: User enters incorrect Login
Given I have an account
And I am not logged in
When I enter an incorrect Login
Then I see a login error message
And I should not be logged in
Scenario: User enters incorrect password
Given I have an account
And I am not logged in
When I enter an incorrect password
Then I see a login error message
And I should not be logged in
Scenario: User logs in successfully
Given I have an account
And I am not logged in
When I enter my correct login
And I enter my correct password
Then I see a successful login message
When I return to the application
Then I should still be logged in
Here is the env.rb file;
require 'cucumber/rails'
require 'webrat'
require 'cucumber/rails/world'
require 'webrat/core/matchers'
Webrat.configure do |config|
config.mode = :rack
config.open_error_files = false
end
World(Webrat::Methods)
World(Webrat::Matchers)
ActionController::Base.allow_rescue = false
begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
Cucumber::Rails::World.use_transactional_fixtures = false
class ActiveSupport::TestCase
setup do |session|
session.host! "localhost:3001"
end
end
rails/blob/master/features/choose_javascript_database_strategy.feature
Cucumber::Rails::Database.javascript_strategy = :truncation
Here is the gemfile:
# Use jquery as the JavaScript library
gem "jquery-rails", "~> 2.3.0"
gem 'jquery-ui-rails', '4.1.2'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :development, :test do
gem 'rspec-rails', '~> 3.0.0'
gem 'cucumber-rails', require: false
gem "webrat"
gem 'factory_girl_rails'
gem 'selenium-client'
gem 'capybara'
gem 'database_cleaner'
end
Ok, so your step is this:
Then /^I see a login error message$/ do
visit home_path
response.should contain("Welcome admin")
end
And the error you're getting is: RSpec::Expectations::ExpectationNotMetError
I think it's just a case of you're expectation is wrong, but is at least a bit misleading. We should actually see an error (something like "Cannot login") but we are looking for "Welcome admin" which seems more like a welcome message.
We can debug this by placing puts response.body before the expectation to see what is being rendered.
It may also be that the cucumber isn't waiting for the request to finish. We could try adding find('#some-element') which will wait for a few seconds before failing if it cannot find an element.
Edit: Also, I just noticed the feature that you were running isn't the one you included (login.feature) so you're trying to see an error message without attempting an incorrect login.
I am testing force_ssl in my Rails 4 app , so I added in the todos_controller:
class Users::TodosController < ApplicationController
....
force_ssl :only => [:test_ssl] unless Rails.env.development?
I added into config/application.rb
config.force_ssl = false
I modified vhost , restarted apache ...
when the user request ...todos/test_ssl, the https request is performed, ok
however , once being on this pas , the user go back to the home page, the request is still performed with https , it doesn't swithc back to http...
should I insert force_ssl = false in the other controllers ? I thought the config parameter would be avaolable for all other controllers ... am I wrong ? or should I use the gem rack-ssl-enforcer ?