I'm want to test my login through facebook. Im using pure omniauth, w/o Devise. I check the wiki page and do following:
helper for request specs
module IntegrationSpecHelper
def login_with_oauth(service = :facebook)
visit "/auth/#{service}"
end
end
spec_helper.rb
RSpec.configure do |config|
config.include IntegrationSpecHelper, :type => :request
end
Capybara.default_host = 'http://example.org'
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:facebook, {
:provider => 'facebook',
:uid => '12345',
:user_info => {
:name => 'dpsk'
}
})
my spec
require 'spec_helper'
describe 'facebook' do
it "should login with facebook", :js => true do
login_with_oauth
visit '/'
page.should have_content("dpsk")
end
end
#OmniAuth routes
match "/auth/:provider/callback" => "sessions#create"
match "/signout" => "sessions#destroy", :as => :signout
match "/signin" => "sessions#signin", :as => :signin
match "/auth/failure" => "sessions#failure", :as => :auth_failure
But in spec nothing returns instead of my mock i got an error:
Failure/Error: visit "/auth/facebook"
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
Where is my error?
My problem was in the mock, its has wrong structure.
OmniAuth.config.mock_auth[:facebook] = {
'user_info' => {
'name' => 'Mario Brothers',
'image' => '',
'email' => 'dpsk#email.ru' },
'uid' => '123545',
'provider' => 'facebook',
'credentials' => {'token' => 'token'}
}
This structure worked for me (December 2016)
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({
'provider' => 'facebook',
'uid' => '123545',
'info' => {
'email' => 'dpsk#email.ru',
'name' => 'Mario Brothers',
'image' => '' },
'credentials'=> {
'token'=> '12345',
'expires_at' => 1486718672,
'expires' => true },
'extra' => {
'raw_info' => {
'email' => 'dpsk#email.ru',
'name' => 'Mario Brothers',
'id' => '12345' }
}
})
Related
I am using Elfinder Rails for Media Manger in my application. I am working on to store the media files to Amazon S3 storage. I try to use the gem el_finder_s3. I created bucket and provided all the configurations like.
def elfinder
ElFinderS3::Connector.new(
:mime_handler => ElFinderS3::MimeType,
:root => '/',
:url => 's3.ap-southeast-1.amazonaws.com',
:thumbs => true,
:thumbs_size => 100,
:thumbs_directory => 'thumbs',
:home => t('admin.media.home'),
:original_filename_method => lambda { |file| "#{File.basename(file.original_filename, File.extname(file.original_filename)).parameterize}#{File.extname(file.original_filename)}" },
:default_perms => {:read => true, :write => true, :rm => true, :hidden => false},
:server => {
:bucket_name => 'bucket_name',
:region => 'ap-southeast-1',
:access_key_id => 'acces_key',
:secret_access_key => 'secret_key',
:cdn_base_path => 's3.ap-southeast-1.amazonaws.com'
}
).run(params)
end
Rails application is connect with S3 but elfinder doesn't show the file contents. I checked the bucket, thumb folder was created but elfinder was unable to load the contents.
Please help me to fix it.
It is fixed with the update of the above script. Here is the updated script.
def elfinder
h, r = ElFinderS3::Connector.new(
:mime_handler => ElFinderS3::MimeType,
:root => '/',
:url => 's3.ap-southeast-1.amazonaws.com',
:thumbs => true,
:thumbs_size => 100,
:thumbs_directory => 'thumbs',
:home => t('admin.media.home'),
:original_filename_method => lambda { |file| "#{File.basename(file.original_filename, File.extname(file.original_filename)).parameterize}#{File.extname(file.original_filename)}" },
:default_perms => {:read => true, :write => true, :rm => true, :hidden => false},
:server => {
:bucket_name => 'bucket_name',
:region => 'ap-southeast-1',
:access_key_id => 'acces_key',
:secret_access_key => 'secret_key',
:cdn_base_path => 's3.ap-southeast-1.amazonaws.com'
}
).run(params)
headers.merge!(h)
if r.empty?
(render :nothing => true) and return
end
render :json => r, :layout => false
end
Someone is having this issue? or now why this is happing on configuring the paypal sdk adaptive?
place the configuration on the yml did not show this message but did not work either, so
i place the sdk configure on: buy action
and on the log shows:
line 58 is PayPal::SDK.configure
NoMethodError (undefined method []' for false:FalseClass):
app/controllers/orders_controller.rb:58:inbuy'
def buy
require 'paypal-sdk-adaptivepayments'
PayPal::SDK.configure(
:mode => "live", # Set "live" for production
:app_id => "APP-xxxxx",
:username => "xxxx.yyyy.com",
:password => "xxxx",
:signature => "xxxxx" )
#api = PayPal::SDK::AdaptivePayments.new
order = Order.find(params[:id])
#pay = #api.build_pay({
:actionType => "PAY",
:cancelUrl => carts_url,
:currencyCode => "US",
:feesPayer => "SENDER",
:ipnNotificationUrl => ipn_notification_order_url(order),
:receiverList => {
:receiver => [{
:email => seller#seller.com,
:amount => 1.0,
:primary => true},
{:email => buyer#buyer.com,
:amount => 1.0,
:primary => false}]},
:returnUrl => carts_url })
#response = #api.pay(#pay)
# Access response
if #response.success? && #response.payment_exec_status != "ERROR"
#response.payKey
redirect_to #api.payment_url(#response) # Url to complete payment
else
#response.error[0].message
redirect_to fail_order_path(order)
end
end
I tried ccavenue but I'am getting this error. paypal is working fine.
undefined methodpayment_service_for'`
This is my controller action
def create
#subscription = Subscription.new(subscription_params)
#programme = Programme.find(subscription_params[:programme_id])
rand_number = rand.to_s[2..11]
#programme.update_attributes(:invoice_id => rand_number)
session[:programme_id]=#programme.id
session[:invoice_id]=#programme.invoice_id
#paypal = PaypalPayment.create(:material_type => 'Programmes',:invoice_id => rand_number,:currency => #programme.currency, :status => 'Processing', :created_at => DateTime.now, :user_id => current_user.specific.id, :email_id => current_user.specific.email, :programme_id => #programme.id,:amount => #programme.price_paisas)
#paypal.save
`session[:paypal_id]=#paypal.id
logger.info #programme.inspect
if subscription_params[:payment_type] == 'paypal'
item_details=[]
if #programme.currency == 'INR'
price = #programme.price.exchange_to('USD')
else
price = #programme.price
end
logger.info price.inspect
item_details << {:name => #programme.title, :quantity => '1', :amount => price.fractional}
response = EXPRESS_GATEWAY.setup_purchase(price.fractional,
:items => item_details,
:currency => "USD",
:order_id => #programme.invoice_id,
:return_url => students_success_url,
:cancel_return_url => students_root_url
)
logger.info response.inspect
session[:programme_price]=price
return redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
elsif subscription_params[:payment_type] == 'ccavenue'
payment_service_for #programme.invoice_id, CCAVENUE_ACCOUNT,
:amount => #programme.price.fractional,
:currency => 'INR',
:service => :ccavenue do |service|
service.customer :name => current_user.name,
:email => current_user.email,
:phone => current_user.mobile
service.redirect :return_url => students_success_url
submit_tag 'Proceed to payment'
end
end
end
end`
I referred this link:
https://github.com/meshbrain/active_merchant_ccavenue
The payment_service_for is the view helper of the Active Merchant gem. You should use this method inside views or you should include view helpers inside your controller.
Can anyone help me with a bit of code:), I have the fallowing hash
selector = {
:fields => ['Id'],
:predicates => [
{:field => 'grpId', :operator => 'EQUALS', :values => [params_id]},
{:field => 'CrType', :operator => 'EQUALS', :values => ['KEYWORD']}
]
}
And I would like to create a condition for this line:
{:field => 'grpId', :operator => 'EQUALS', :values => [params_id]},
to be performed only if the params_id is not empty.
Thank you
selector = {
:fields => ['Id'],
:predicates => [
params_id ? {:field => 'grpId', :operator => 'EQUALS', :values => [params_id]} : nil,
{:field => 'CrType', :operator => 'EQUALS', :values => ['KEYWORD']}
].compact
}
I'm using link_to_remote to update a div asynchronously, but it does not work. I have to refresh the page in order to see the change.
I use this to generate the links.
http://ruby.pastebin.com/m1d83be81
"padding-left:30px", :display => "table-row" ) do %>
{ :success => 'entry_' + entry.id.to_s},
:url =>{ :controller => :entries, :action => :increment ,:id => entry.id},
:with => "'amount=' +prompt('Amount')")%>
{ :success => 'entry_' + entry.id.to_s},
:url =>{ :controller => :entries, :action => :decrement ,:id => entry.id},
:with => "'amount=' +prompt('Amount')")%>
{ :success => 'entry_' + entry.id.to_s},
:url =>{ :controller => :entries, :action => :update ,:id => entry.id},
:with => "'amount=' +prompt('Amount')")%>
The corresponding actions all look like this:
def increment
#entry = Entry.find(params[:id])
#entry.amount += params[:amount].to_i
#entry.save!
render :partial=>"entry", :object=>#entry
end
Remove the :success tag in your update clause and test:
:update => 'entry_' + entry.id.to_s
I have found it helpful to specify the div to be updated in an :update in the controller action.