In my spec/models/user_spec.rb I have the next:
require 'spec_helper'
describe User do
before { 5.times { FactoryGirl.create(:sport) } }
before { let(:user) { FactoryGirl.create(:user) } }
...
end
But when running my user_spec.rb I'm getting this error:
Failure/Error: before { let(:user) { FactoryGirl.create(:user) } }
NoMethodError:
undefined method `let' for #<RSpec::Core::ExampleGroup::Nested_1:0x000001043033b0>
Which is weird because my specs have been working until now, and I haven't changed anything...
Here is my gemfile: https://gist.github.com/4690919
Here is my spec_helper.rb: https://gist.github.com/4690935
I'd appreciate any help, thanks
I don't know why it was working before, but you should never have a let block inside of a before block. It should be called from within a describe (or context) block, like this:
describe User do
let(:user) { FactoryGirl.create(:user) }
before { 5.times { FactoryGirl.create(:sport) } }
....
See the documentation for details.
Related
I have a controller with a particular method to login:
public function login() {
if ($this->request->is('post')){
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
// not logged
$this->Flash->error('Your username or password is incorrect');
}
}
and default route looks like
Router::scope('/', function (RouteBuilder $routes) {
$routes->fallbacks(DashedRoute::class);
});
after user is logged in CakePHP throws an error
Error: A route matching "/" could not be found.
None of the currently connected routes match the provided parameters.
Add a matching route to config/routes.php
when IMO it should to redirect to the page (based on a related controller) from where login method was executed.
Login code is based on that tutorial.
Any thoughts?
To solve this issue:
Please update the below lines in routes.php file
Router::defaultRouteClass('DashedRoute');
Router::scope('/', function (RouteBuilder $routes) {
$routes->connect('/', ['controller' => 'users', 'action' => 'index']);
$routes->fallbacks('DashedRoute');
});
Plugin::routes();
Please do create index() in users controller.
Let me know if any issue.
Hi I'm trying to test react native facebook sdk for facebook login. Using below code I'm able to successfully give in my credentials and log in to app. My question is i'm not getting the alert message or console.log output. Even the debugger statement seems not working. Can someone help me to figure out how to correctly handle onLoginFinished event.
<View>
<LoginButton
// publishPermissions={["none"]}
readPermissions = {["public_profile"]}
onLoginFinished={
(error, result) => {
debugger;
if (error) {
alert("login has error: " + result.error);
console.log("Error occured");
} else if (result.isCancelled) {
alert("login is cancelled.");
console.log("Login canceled");
} else {
// I don't see this alert or console.log anywhere
alert("Login success");
console.log("Login Success");
} // end else
}
}
onLogoutFinished={() => { alert("User logged out");}}
/>
</View>
What I found is that You need to always build your app again with the command react-native run-android or react-native run-ios for the changes to actually take effect.
I found my problem after going through this.https://github.com/facebook/react-native-fbsdk In my MainActivity class I was using CallbackManager instance locally initiated. After referring to CallbackManager instance of MainApplication class, onLoginFinished functioned triggered!! :)
please refer : https://reactnativecode.com/facebook-login-integration/
i think you debugger have issue but i am using this code thats working fine. can you check onLoginFinished method is called or not .
<LoginButton
publishPermissions={[“publish_actions”]}
onLoginFinished={
(error, result) => {
(error) {
alert(“Login failed with error: “ + result.error);
} else if (result.isCancelled) {
alert(“Login was cancelled”);
} else {
alert(“Login was successful with permissions: “
+ result.grantedPermissions)
}
}
}
onLogoutFinished={() => alert(“User logged out”)}
/>
Good Day,
I am trying to sign out an auth2 client. This process was working fine before I upgraded my router to fit in with new RC requirements. Now it seems as if the auth2 object is cleared or lost along the way from signing in to signing out.
Here is my sign out tag:
<a role="button" (click)="signOut()" style="padding-left: 30px;">Log out</a>
it simply calls a signOut() function found in navbar.component.ts (See below)
signOut() {
var auth2 = this._navigationService.getAuth2();
auth2.signOut().then(function () {
});
console.log('User signed out.');
sessionStorage.clear();
localStorage.clear();
this.router.navigate(['Login'])
window.location.reload()
}
here is the navigationService code it is calling:
import { Injectable } from '#angular/core';
#Injectable()
export class NavigationService {
onEditMode:boolean;
auth2:any;
constructor() {
this.onEditMode=true;
}
getEditMode(){
return this.onEditMode;
}
setEditMode(editMode:boolean){
this.onEditMode=editMode;
}
setAuth2(auth2:any){
this.auth2=auth2;
}
getAuth2(){
return this.auth2;
}
}
Here is my login.component.ts which sets the auth2 object seen in navigationService.ts:
onGoogleLoginSuccess = (loggedInUser) => {
this.isLoading=true;
console.log(loggedInUser)
this._navigationService.setAuth2(gapi.auth2.getAuthInstance());
console.log("Google gapi" + gapi.auth2.getAuthInstance());
sessionStorage.setItem('gapi',gapi.auth2.getAuthInstance());
this._zone.run(() => {
this.userAuthToken = loggedInUser.hg.access_token;
this.userDisplayName = loggedInUser.getBasicProfile().getName();
var strClientID = document.getElementsByTagName('meta')['google-signin-client_id'].getAttribute('content')
this.objTrimbleAuthentication.ClientID = document.getElementsByTagName('meta')['google-signin-client_id'].getAttribute('content');
this.objTrimbleAuthentication.IDToken = loggedInUser.getAuthResponse().id_token;
this._trimbleAuthenticationService.sendAndVerify(this.objTrimbleAuthentication).subscribe(data=>{
if(data.tokenIsValid==true){
sessionStorage.setItem('S_USER_EMAIL',loggedInUser.getBasicProfile().getEmail());
sessionStorage.setItem('S_USER_NAME',loggedInUser.getBasicProfile().getName());
sessionStorage.setItem('S_ID_TOKEN',this.userAuthToken);
this.objExternalBindingModel.ExternalAccessToken=this.userAuthToken;
this.objExternalBindingModel.Provider="Google";
this.objExternalBindingModel.UserName = loggedInUser.getBasicProfile().getName();
this._LoginService.obtainLocalAccessToken(this.objExternalBindingModel).subscribe(data=>{
// console.log(data);
this.isLoading=false;
this._router.navigate(['/Home']);
sessionStorage.setItem("access_token",data.access_token);
},error=>{
console.log(error);
})
}else{
this.isLoading= false;
this.showModal('#trimbleAuthError');
}
}, error=>{
})
});
}
onGoogleLoginSuccess is called from login.component.html:
<div style="margin-left:8% !important" id="{{googleLoginButtonId}}"></div>
So this process was working fine until I update my router to use the latest Angular2 Release Candidate. I am out of ideas on what could possibly be causing the following error when I click the sign out button:
Error in component.html/navbar.component.html:12:33
ORIGINAL EXCEPTION: TypeError: Cannot read property 'signOut' of undefined
if you need any other information or components please ask I hope I have given enough information. As I said it was working so keep that in mind, please.
Update
Waiting for additional info ...
In the following code, auth2:any; is undeclared. Is setAuth2 called anywhere before signOut()?
import { Injectable } from '#angular/core';
#Injectable()
export class NavigationService {
onEditMode:boolean;
auth2:any;
constructor() {
this.onEditMode=true;
}
getEditMode(){
return this.onEditMode;
}
setEditMode(editMode:boolean){
this.onEditMode=editMode;
}
setAuth2(auth2:any){
this.auth2=auth2;
}
getAuth2(){
return this.auth2;
}
}
Base on limited information and code posted, my guess is a logical bug in the logout process.
In signOut(), the window.location.reload() reload the page at the current url, which also clear all variables/objects. However, after reload, your app properly try to do signout again (due to url?).
In your navbar.component, you may need to add more logic in ngInit() to handle the situation.
Or can your code work without window.location.reload()? It seems odd to use that with angular2, especially with routing.
Right, the solution i found to the above question was that signing out using localhost will not work. So i just used this block of code when deploying the website and keep it commented out when running the website on localhost.
this is my signOut() function found in navbar.component.ts:
signOut() {
//////////////////////////////////////// Uncomment block for live deployment //////////////////////////////
// var auth2 = gapi.auth2.getAuthInstance();
// auth2.signOut().then(function () {
// console.log('User signed out.');
// });
//////////////////////////////////////////////////////////////////////////////////////////////////////////
sessionStorage.clear();
localStorage.clear();
this.router.navigate(['/']);
window.location.reload();
}
although getAuthInstance gives an error when trying to run it in localhost, deploying the web application to a server seems to work fine.
My server responds with a 400 status if a book title already exists. The ember app catches the error and does a errors.add with the attribute name and error detail. For some reason when a receive the 400 when I change the title the form submit button is dead. I found that when I eliminate the errors.add line the problem goes away.
Here is my action:
import Ember from 'ember';
import DS from 'ember-data';
export default Ember.Route.extend({
model() {
return this.store.createRecord('book');
},
setupController: function(controller, model) {
controller.set('book', model);
controller.set('errors', DS.Errors.create());
},
actions: {
createBook: function(book) {
var _this = this;
var errors = _this.controllerFor('books.new').get('errors');
book.save().then(function(book) {
_this.transitionTo('books.book', book);
}).catch(function(response) {
response.errors.forEach(function(error) {
var attribute = error.source.pointer.split('/')[3];
//This line causes the problem---> errors.add(attribute, error.detail);
});
});
}
}
});
This is the response:
res.status(400).send({
errors: [
{
status: "400",
source: { pointer: '/data/attributes/title' },
title: "Invalid Attribute",
detail: 'must be unique'
}
]
});
How would I write this block function in swift. I've read through on the subject but the syntax just doesn't make much sense to me.
MyAppRequest *request = [_agent login];
[request sendWithLoadMessage:#"Signing In"
successMessage:#"Signed In"
failureMessage:#"Failed to log in"
recoveryOptions:#"If you keep having trouble, try going to http://mystrou.firehosehelp.com and try loggin in there. If that fails, try resetting your password"
success:^(MyAppResponse *response) {
PREFS.authToken = _agent.accessToken;
[_delegate loginViewController:self loggedInAgent:_agent];
} failure:^(MyAppResponse *response) {
}];
It's not that hard actually. called closures in Swift).
public func someFunction(success: (response: AnyObject!) -> Void, failure: (error: NSError?) -> Void) {
}
And here's how you call it.
someFunction(success: { (response) -> Void in
// Handle success response
}) { (error?) -> Void in
// Do error handling stuff
}
In your case, I'm getting this block handles some server response. Most probably logging in. The success block would be called if the network operation succeeds. Inside it, you save the received access token from your server.
The failure block is called if the network request fails. You might want to log the error out, display an alert to the user stuff like that in it.
If you're confused about the syntax I suggest refer to these two sites. For Objective-C block syntax and for Swift closure syntax.
thanks to #isuru I figured this out:
let request: MyAppRequest = agent .login()
request .sendWithLoadMessage("Signing in",
successMessage: "Signed in",
failureMessage: "Failed to login",
recoveryOptions: "Figuring it out",
success: { (response: MyAppResponse!) -> Void in MyAppSettings().authenticatingToken = agent.accessToken
}) { (response: MyAppResponse!) -> Void in
var alert = UIAlertController(title: "Oops!", message: "You haven't figured out the token thing!", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}