Automatic redirect to login page after a certain time
I am using form authentication. My code in web.config is:
<authentication mode="Forms">
<forms loginUrl="~/Home/Index" timeout="5" />
</authentication>
I've used [Authorize] at the head of the actions, that need authentication
to access. As my configuration in web.config after five minutes an user is
redirected to "../Home/Index" if he/she tries to access an action or load
a page that is need authentication to access. Is there any way to do it
automatically. I mean if the system is idle, like though no one is using
the system after five minutes it will automatically redirect to
"../Home/Index" page.
Busie
Sunday, 1 September 2013
WlanEnumInterfaces don't return Guid C# Whit P/Invoke
WlanEnumInterfaces don't return Guid C# Whit P/Invoke
Hy Guy i have a a problem whit c# to call a native function
wlanenuminterfaces the function return ok = (0) but i don't know why...
the Guid of interface is all {000000000000000000} why? someone can help me
? thanks so much
Hy Guy i have a a problem whit c# to call a native function
wlanenuminterfaces the function return ok = (0) but i don't know why...
the Guid of interface is all {000000000000000000} why? someone can help me
? thanks so much
Saturday, 31 August 2013
PHP Map $_POST data to object
PHP Map $_POST data to object
This is more of a best practice question than anything.
Let's say I have a form:
<form action="self.php" method="POST">
<input type="text" name="aA" />
<input type="text" name="aB" />
<input type="text" name="aC" />
</form>
And a corresponding class in PHP:
class A
{
public function getA(){
return $this->a;
}
public function setA($a){
$this->a = $a;
}
public function getB(){
return $this->b;
}
public function setB($b){
$this->b = $b;
}
public function getC(){
return $this->c;
}
public function setC($c){
$this->c = $c;
}
private $a;
private $b;
private $c;
}
And somehow I manage to send the data from the form. Now, I need the form
data transformed into an instance of A.
What I'm currently doing is the following:
abstract class AStrategy {
public function doMapping(){
$a = new A();
if (isset($_POST['aA']) === true) {
$a->setA($_POST['aA']);
}
... (same for b and c)
return $a; //A completely mapped object
}
}
And I'm extremely aware this is pretty much bad practice (violating DRY).
What's the best practice to do this?
What if I have a complex object tree? What if I need to map related
objects at the same time?
Who should do the mapping? Who should create the object and such?
Thank you beforehand.
This is more of a best practice question than anything.
Let's say I have a form:
<form action="self.php" method="POST">
<input type="text" name="aA" />
<input type="text" name="aB" />
<input type="text" name="aC" />
</form>
And a corresponding class in PHP:
class A
{
public function getA(){
return $this->a;
}
public function setA($a){
$this->a = $a;
}
public function getB(){
return $this->b;
}
public function setB($b){
$this->b = $b;
}
public function getC(){
return $this->c;
}
public function setC($c){
$this->c = $c;
}
private $a;
private $b;
private $c;
}
And somehow I manage to send the data from the form. Now, I need the form
data transformed into an instance of A.
What I'm currently doing is the following:
abstract class AStrategy {
public function doMapping(){
$a = new A();
if (isset($_POST['aA']) === true) {
$a->setA($_POST['aA']);
}
... (same for b and c)
return $a; //A completely mapped object
}
}
And I'm extremely aware this is pretty much bad practice (violating DRY).
What's the best practice to do this?
What if I have a complex object tree? What if I need to map related
objects at the same time?
Who should do the mapping? Who should create the object and such?
Thank you beforehand.
Is this dependency injection?
Is this dependency injection?
A simple question that is perhaps a bit silly. Is this dependency
injection? I do not mean a DI container.
Foo depends on an instance of Bar. Foo gets an instance of Bar passed by
constructor and does not care even for the initialization.
public class Foo
{
public Foo(IBar bar)
{
DoSomething(bar);
}
private void DoSomething(IBar bar)
{
// ...
}
}
public class Bar : IBar
{
// ...
}
Is passing an instance of Bar to the constructor a dependency injection?
Especially constructor injection.
A simple question that is perhaps a bit silly. Is this dependency
injection? I do not mean a DI container.
Foo depends on an instance of Bar. Foo gets an instance of Bar passed by
constructor and does not care even for the initialization.
public class Foo
{
public Foo(IBar bar)
{
DoSomething(bar);
}
private void DoSomething(IBar bar)
{
// ...
}
}
public class Bar : IBar
{
// ...
}
Is passing an instance of Bar to the constructor a dependency injection?
Especially constructor injection.
Sequelize find primary key of table using table column name
Sequelize find primary key of table using table column name
I'm building a chat room with a messages table and a rooms table.
Rooms table:
+----------+----+
| roomname | id |
+----------+----+
| beach | 1 |
+----------+----+
| downtown | 2 |
+----------+----+
Messages table:
+----------+----------------------------------+----+--------+
| username | message | id | roomId |
+----------+----------------------------------+----+--------+
| emilio | this place is really really cool | 1 | 1 |
| moneym | this place is really really cool | 2 | 2 |
| joe | this place is really really cool | 3 | 2 |
| sandy | this place is really really cool | 4 | 1 |
+----------+----------------------------------+----+--------+
Room.hasMany(Message);
Message.belongsTo(Room);
I'm using Sequelize.js to find the room name using Room.find(). Is there a
way to pass in the room name and have the table look up the id
automatically?
Something like Message.build({username:username, message: message, roomId:
{where: {roomname: 'beach'}});
exports.getMessages = function(roomname, res) {
Room.find({where: {roomname: roomname}}).success(function(resultingRoom) {
var newMessage = Message.build({username: username, message: message,
roomId: resultingRoom.id});
newMessage.save()
});
};
I'm building a chat room with a messages table and a rooms table.
Rooms table:
+----------+----+
| roomname | id |
+----------+----+
| beach | 1 |
+----------+----+
| downtown | 2 |
+----------+----+
Messages table:
+----------+----------------------------------+----+--------+
| username | message | id | roomId |
+----------+----------------------------------+----+--------+
| emilio | this place is really really cool | 1 | 1 |
| moneym | this place is really really cool | 2 | 2 |
| joe | this place is really really cool | 3 | 2 |
| sandy | this place is really really cool | 4 | 1 |
+----------+----------------------------------+----+--------+
Room.hasMany(Message);
Message.belongsTo(Room);
I'm using Sequelize.js to find the room name using Room.find(). Is there a
way to pass in the room name and have the table look up the id
automatically?
Something like Message.build({username:username, message: message, roomId:
{where: {roomname: 'beach'}});
exports.getMessages = function(roomname, res) {
Room.find({where: {roomname: roomname}}).success(function(resultingRoom) {
var newMessage = Message.build({username: username, message: message,
roomId: resultingRoom.id});
newMessage.save()
});
};
Cucumber Test acting in a strange way
Cucumber Test acting in a strange way
First its based on Rails 3 on Action so, i will type every thing i have
tried and the errors I have got so anybody can help me and if there any
important file i should added to my question please tell...also maybe the
title of the question not good enough but i don't know what title should i
give to cucumber questions.
In the book the author was trying to hide edit and delete links so
non-signed user and signed in user won't be able to see it except they are
admins.
for authentication he is using devise 1.4.3 and cucumber version 1.0.6, i
am on chapter 7 specifically on 7.3.3.
Now the steps in the book said we will wirte a cucumber test for hiding
edit and delete links and that was the code of it:
Scenario: Edit project link is hidden for non-signed-in users
Given I am on the homepage
When I follow "TextMate 2"
Then I should not see the "Edit Project" link
Scenario: Edit project link is hidden for signed-in user
Given I am signed in as "user@ticketee.com"
When I follow "TextMate 2"
Then I should not see the "Edit Project" link
Scenario: Edit project link is shown to admin
Given I am signed in as "admin@ticketee.com"
When I follow "TextMate 2"
Then I should see the "Edit Proeject" link
Scenario: Delete project link is hidden for non-signed-in users
Given I am on the homepage
When I follow "TextMate 2"
Then I should not see the "Delete Project" link
Scenario: Delete project link is hidden for signed-in users
Given I am signed in as "user@ticketee.com"
When I follow "TextMate 2"
Then I should not see the "Delete Project" link
Scenario: Delete project link is shown to admins
Given I am signed in as "admin@ticketee.com"
When I follow "TextMate 2"
Then I should see the "Delete Project" link
then when tried to run the test i got a problem about missing feature
(although in the book the test is passing and then should be pushed to
github but for me it not passing ) so i have added this at the top of my
code:
Feature: Hidden Links
In order to clean up the user experience
As the system
I want to hide links from users who can't act on them
Now when i am trying to run the test i am getting this error:
➜ ticketee git:(master) ✗ bin/cucumber
features/hidden_links.feature
Rack::File headers parameter replaces cache_control after Rack 1.5.
Using the default profile...
Feature: Hidden Links
In order to clean up the user experience
As the system
I want to hide links from users who can't act on them
Scenario: Edit project link is hidden for non-signed-in users #
features/hidden_links.feature:6
Given I am on the homepage #
features/step_definitions/web_steps.rb:44
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Unable to find link "TextMate 2" (Capybara::ElementNotFound)
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow
"([^"]*)"$/'
features/hidden_links.feature:8:in `When I follow "TextMate 2"'
Then I should not see the "Edit Project" link #
features/hidden_links.feature:9
Undefined step: "I should not see the "Edit Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:9:in `Then I should not see the "Edit
Project" link'
Scenario: Edit project link is hidden for signed-in user #
features/hidden_links.feature:11
Given I am signed in as "user@ticketee.com" #
features/hidden_links.feature:12
Undefined step: "I am signed in as "user@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:12:in `Given I am signed in as
"user@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should not see the "Edit Project" link #
features/hidden_links.feature:14
Undefined step: "I should not see the "Edit Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:14:in `Then I should not see the "Edit
Project" link'
Scenario: Edit project link is shown to admin #
features/hidden_links.feature:16
Given I am signed in as "admin@ticketee.com" #
features/hidden_links.feature:17
Undefined step: "I am signed in as "admin@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:17:in `Given I am signed in as
"admin@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should see the "Edit Proeject" link #
features/hidden_links.feature:19
Undefined step: "I should see the "Edit Proeject" link"
(Cucumber::Undefined)
features/hidden_links.feature:19:in `Then I should see the "Edit
Proeject" link'
Scenario: Delete project link is hidden for non-signed-in users #
features/hidden_links.feature:21
Given I am on the homepage #
features/step_definitions/web_steps.rb:44
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Unable to find link "TextMate 2" (Capybara::ElementNotFound)
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow
"([^"]*)"$/'
features/hidden_links.feature:23:in `When I follow "TextMate 2"'
Then I should not see the "Delete Project" link #
features/hidden_links.feature:24
Undefined step: "I should not see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:24:in `Then I should not see the
"Delete Project" link'
Scenario: Delete project link is hidden for signed-in users #
features/hidden_links.feature:26
Given I am signed in as "user@ticketee.com" #
features/hidden_links.feature:27
Undefined step: "I am signed in as "user@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:27:in `Given I am signed in as
"user@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should not see the "Delete Project" link #
features/hidden_links.feature:29
Undefined step: "I should not see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:29:in `Then I should not see the
"Delete Project" link'
Scenario: Delete project link is shown to admins #
features/hidden_links.feature:31
Given I am signed in as "admin@ticketee.com" #
features/hidden_links.feature:32
Undefined step: "I am signed in as "admin@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:32:in `Given I am signed in as
"admin@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should see the "Delete Project" link #
features/hidden_links.feature:34
Undefined step: "I should see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:34:in `Then I should see the "Delete
Project" link'
Failing Scenarios:
cucumber features/hidden_links.feature:6 # Scenario: Edit project link is
hidden for non-signed-in users
cucumber features/hidden_links.feature:21 # Scenario: Delete project link
is hidden for non-signed-in users
6 scenarios (2 failed, 4 undefined)
18 steps (2 failed, 4 skipped, 10 undefined, 2 passed)
0m0.187s
You can implement step definitions for undefined steps with these snippets:
Then(/^I should not see the "(.*?)" link$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Given(/^I am signed in as "(.*?)"$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Then(/^I should see the "(.*?)" link$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Then I added this to my code in order to trying to make my test pass:
Background: Given there are the following users: | email | password |
admin | | user@ticketee.com | password | false | | admin@ticketee.com |
password | true | And there is a project called "TextMate 2"
Then I run the test and got this error:
➜ ticketee git:(master) ✗ bin/cucumber
features/hidden_links.feature
Rack::File headers parameter replaces cache_control after Rack 1.5.
Using the default profile...
Feature: Hidden Links
In order to clean up the user experience
As the system
I want to hide links from users who can't act on them
Background: #
features/hidden_links.feature:6
Given there are the following users: #
features/step_definitions/user_steps.rb:1
| email | password | admin |
| user@ticketee.com | password | false |
| admin@ticketee.com | password | true |
And there is a project called "TextMate 2" #
features/step_definitions/project_steps.rb:1
Scenario: Edit project link is hidden for non-signed-in users #
features/hidden_links.feature:13
Given I am on the homepage #
features/step_definitions/web_steps.rb:44
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
undefined method `admins_only' for #<#<Class:0x9c16994>:0x9d134b4>
(ActionView::Template::Error)
./app/views/projects/show.html.erb:3:in
`_app_views_projects_show_html_erb___713092924_82350660'
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow
"([^"]*)"$/'
features/hidden_links.feature:15:in `When I follow "TextMate 2"'
Then I should not see the "Edit Project" link #
features/hidden_links.feature:16
Undefined step: "I should not see the "Edit Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:16:in `Then I should not see the "Edit
Project" link'
Scenario: Edit project link is hidden for signed-in user #
features/hidden_links.feature:18
Given I am signed in as "user@ticketee.com" #
features/hidden_links.feature:19
Undefined step: "I am signed in as "user@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:19:in `Given I am signed in as
"user@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should not see the "Edit Project" link #
features/hidden_links.feature:21
Undefined step: "I should not see the "Edit Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:21:in `Then I should not see the "Edit
Project" link'
Scenario: Edit project link is shown to admin #
features/hidden_links.feature:23
Given I am signed in as "admin@ticketee.com" #
features/hidden_links.feature:24
Undefined step: "I am signed in as "admin@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:24:in `Given I am signed in as
"admin@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should see the "Edit Proeject" link #
features/hidden_links.feature:26
Undefined step: "I should see the "Edit Proeject" link"
(Cucumber::Undefined)
features/hidden_links.feature:26:in `Then I should see the "Edit
Proeject" link'
Scenario: Delete project link is hidden for non-signed-in users #
features/hidden_links.feature:28
Given I am on the homepage #
features/step_definitions/web_steps.rb:44
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
undefined method `admins_only' for #<#<Class:0x9c16994>:0xaa71660>
(ActionView::Template::Error)
./app/views/projects/show.html.erb:3:in
`_app_views_projects_show_html_erb___713092924_82350660'
/home/dexter/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.12/lib/action_view/template.rb:145:in
`block in render'
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow
"([^"]*)"$/'
features/hidden_links.feature:30:in `When I follow "TextMate 2"'
Then I should not see the "Delete Project" link #
features/hidden_links.feature:31
Undefined step: "I should not see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:31:in `Then I should not see the
"Delete Project" link'
Scenario: Delete project link is hidden for signed-in users #
features/hidden_links.feature:33
Given I am signed in as "user@ticketee.com" #
features/hidden_links.feature:34
Undefined step: "I am signed in as "user@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:34:in `Given I am signed in as
"user@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should not see the "Delete Project" link #
features/hidden_links.feature:36
Undefined step: "I should not see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:36:in `Then I should not see the
"Delete Project" link'
Scenario: Delete project link is shown to admins #
features/hidden_links.feature:38
Given I am signed in as "admin@ticketee.com" #
features/hidden_links.feature:39
Undefined step: "I am signed in as "admin@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:39:in `Given I am signed in as
"admin@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should see the "Delete Project" link #
features/hidden_links.feature:41
Undefined step: "I should see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:41:in `Then I should see the "Delete
Project" link'
Failing Scenarios:
cucumber features/hidden_links.feature:13 # Scenario: Edit project link is
hidden for non-signed-in users
cucumber features/hidden_links.feature:28 # Scenario: Delete project link
is hidden for non-signed-in users
6 scenarios (2 failed, 4 undefined)
30 steps (2 failed, 4 skipped, 10 undefined, 14 passed)
0m0.748s
You can implement step definitions for undefined steps with these snippets:
Then(/^I should not see the "(.*?)" link$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Given(/^I am signed in as "(.*?)"$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Then(/^I should see the "(.*?)" link$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
and that is the show.html.erb where i have admins_only:
<% title(@project.name, "Projects") %>
<h2><%= @project.name %></h2>
<% admins_only do %>
<%= link_to "Edit Project", edit_project_path(@project) %>
<%= link_to "Delete Project", @project, :method => :delete, :confirm =>
"Are you sure you want to delete this project?" %>
<% end %>
<%= link_to "New Ticket", new_project_ticket_path(@project) %>
<ul id= 'tickets'>
<% @project.tickets.each do |ticket| %>
<li>
#<%= ticket.id %> - <%= link_to ticket.title, [@project, ticket] %>
</li>
<% end %>
</ul>
thats what i have tried but failed to solve my problem so help appreciated...
First its based on Rails 3 on Action so, i will type every thing i have
tried and the errors I have got so anybody can help me and if there any
important file i should added to my question please tell...also maybe the
title of the question not good enough but i don't know what title should i
give to cucumber questions.
In the book the author was trying to hide edit and delete links so
non-signed user and signed in user won't be able to see it except they are
admins.
for authentication he is using devise 1.4.3 and cucumber version 1.0.6, i
am on chapter 7 specifically on 7.3.3.
Now the steps in the book said we will wirte a cucumber test for hiding
edit and delete links and that was the code of it:
Scenario: Edit project link is hidden for non-signed-in users
Given I am on the homepage
When I follow "TextMate 2"
Then I should not see the "Edit Project" link
Scenario: Edit project link is hidden for signed-in user
Given I am signed in as "user@ticketee.com"
When I follow "TextMate 2"
Then I should not see the "Edit Project" link
Scenario: Edit project link is shown to admin
Given I am signed in as "admin@ticketee.com"
When I follow "TextMate 2"
Then I should see the "Edit Proeject" link
Scenario: Delete project link is hidden for non-signed-in users
Given I am on the homepage
When I follow "TextMate 2"
Then I should not see the "Delete Project" link
Scenario: Delete project link is hidden for signed-in users
Given I am signed in as "user@ticketee.com"
When I follow "TextMate 2"
Then I should not see the "Delete Project" link
Scenario: Delete project link is shown to admins
Given I am signed in as "admin@ticketee.com"
When I follow "TextMate 2"
Then I should see the "Delete Project" link
then when tried to run the test i got a problem about missing feature
(although in the book the test is passing and then should be pushed to
github but for me it not passing ) so i have added this at the top of my
code:
Feature: Hidden Links
In order to clean up the user experience
As the system
I want to hide links from users who can't act on them
Now when i am trying to run the test i am getting this error:
➜ ticketee git:(master) ✗ bin/cucumber
features/hidden_links.feature
Rack::File headers parameter replaces cache_control after Rack 1.5.
Using the default profile...
Feature: Hidden Links
In order to clean up the user experience
As the system
I want to hide links from users who can't act on them
Scenario: Edit project link is hidden for non-signed-in users #
features/hidden_links.feature:6
Given I am on the homepage #
features/step_definitions/web_steps.rb:44
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Unable to find link "TextMate 2" (Capybara::ElementNotFound)
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow
"([^"]*)"$/'
features/hidden_links.feature:8:in `When I follow "TextMate 2"'
Then I should not see the "Edit Project" link #
features/hidden_links.feature:9
Undefined step: "I should not see the "Edit Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:9:in `Then I should not see the "Edit
Project" link'
Scenario: Edit project link is hidden for signed-in user #
features/hidden_links.feature:11
Given I am signed in as "user@ticketee.com" #
features/hidden_links.feature:12
Undefined step: "I am signed in as "user@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:12:in `Given I am signed in as
"user@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should not see the "Edit Project" link #
features/hidden_links.feature:14
Undefined step: "I should not see the "Edit Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:14:in `Then I should not see the "Edit
Project" link'
Scenario: Edit project link is shown to admin #
features/hidden_links.feature:16
Given I am signed in as "admin@ticketee.com" #
features/hidden_links.feature:17
Undefined step: "I am signed in as "admin@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:17:in `Given I am signed in as
"admin@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should see the "Edit Proeject" link #
features/hidden_links.feature:19
Undefined step: "I should see the "Edit Proeject" link"
(Cucumber::Undefined)
features/hidden_links.feature:19:in `Then I should see the "Edit
Proeject" link'
Scenario: Delete project link is hidden for non-signed-in users #
features/hidden_links.feature:21
Given I am on the homepage #
features/step_definitions/web_steps.rb:44
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Unable to find link "TextMate 2" (Capybara::ElementNotFound)
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow
"([^"]*)"$/'
features/hidden_links.feature:23:in `When I follow "TextMate 2"'
Then I should not see the "Delete Project" link #
features/hidden_links.feature:24
Undefined step: "I should not see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:24:in `Then I should not see the
"Delete Project" link'
Scenario: Delete project link is hidden for signed-in users #
features/hidden_links.feature:26
Given I am signed in as "user@ticketee.com" #
features/hidden_links.feature:27
Undefined step: "I am signed in as "user@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:27:in `Given I am signed in as
"user@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should not see the "Delete Project" link #
features/hidden_links.feature:29
Undefined step: "I should not see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:29:in `Then I should not see the
"Delete Project" link'
Scenario: Delete project link is shown to admins #
features/hidden_links.feature:31
Given I am signed in as "admin@ticketee.com" #
features/hidden_links.feature:32
Undefined step: "I am signed in as "admin@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:32:in `Given I am signed in as
"admin@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should see the "Delete Project" link #
features/hidden_links.feature:34
Undefined step: "I should see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:34:in `Then I should see the "Delete
Project" link'
Failing Scenarios:
cucumber features/hidden_links.feature:6 # Scenario: Edit project link is
hidden for non-signed-in users
cucumber features/hidden_links.feature:21 # Scenario: Delete project link
is hidden for non-signed-in users
6 scenarios (2 failed, 4 undefined)
18 steps (2 failed, 4 skipped, 10 undefined, 2 passed)
0m0.187s
You can implement step definitions for undefined steps with these snippets:
Then(/^I should not see the "(.*?)" link$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Given(/^I am signed in as "(.*?)"$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Then(/^I should see the "(.*?)" link$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Then I added this to my code in order to trying to make my test pass:
Background: Given there are the following users: | email | password |
admin | | user@ticketee.com | password | false | | admin@ticketee.com |
password | true | And there is a project called "TextMate 2"
Then I run the test and got this error:
➜ ticketee git:(master) ✗ bin/cucumber
features/hidden_links.feature
Rack::File headers parameter replaces cache_control after Rack 1.5.
Using the default profile...
Feature: Hidden Links
In order to clean up the user experience
As the system
I want to hide links from users who can't act on them
Background: #
features/hidden_links.feature:6
Given there are the following users: #
features/step_definitions/user_steps.rb:1
| email | password | admin |
| user@ticketee.com | password | false |
| admin@ticketee.com | password | true |
And there is a project called "TextMate 2" #
features/step_definitions/project_steps.rb:1
Scenario: Edit project link is hidden for non-signed-in users #
features/hidden_links.feature:13
Given I am on the homepage #
features/step_definitions/web_steps.rb:44
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
undefined method `admins_only' for #<#<Class:0x9c16994>:0x9d134b4>
(ActionView::Template::Error)
./app/views/projects/show.html.erb:3:in
`_app_views_projects_show_html_erb___713092924_82350660'
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow
"([^"]*)"$/'
features/hidden_links.feature:15:in `When I follow "TextMate 2"'
Then I should not see the "Edit Project" link #
features/hidden_links.feature:16
Undefined step: "I should not see the "Edit Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:16:in `Then I should not see the "Edit
Project" link'
Scenario: Edit project link is hidden for signed-in user #
features/hidden_links.feature:18
Given I am signed in as "user@ticketee.com" #
features/hidden_links.feature:19
Undefined step: "I am signed in as "user@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:19:in `Given I am signed in as
"user@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should not see the "Edit Project" link #
features/hidden_links.feature:21
Undefined step: "I should not see the "Edit Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:21:in `Then I should not see the "Edit
Project" link'
Scenario: Edit project link is shown to admin #
features/hidden_links.feature:23
Given I am signed in as "admin@ticketee.com" #
features/hidden_links.feature:24
Undefined step: "I am signed in as "admin@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:24:in `Given I am signed in as
"admin@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should see the "Edit Proeject" link #
features/hidden_links.feature:26
Undefined step: "I should see the "Edit Proeject" link"
(Cucumber::Undefined)
features/hidden_links.feature:26:in `Then I should see the "Edit
Proeject" link'
Scenario: Delete project link is hidden for non-signed-in users #
features/hidden_links.feature:28
Given I am on the homepage #
features/step_definitions/web_steps.rb:44
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
undefined method `admins_only' for #<#<Class:0x9c16994>:0xaa71660>
(ActionView::Template::Error)
./app/views/projects/show.html.erb:3:in
`_app_views_projects_show_html_erb___713092924_82350660'
/home/dexter/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.12/lib/action_view/template.rb:145:in
`block in render'
./features/step_definitions/web_steps.rb:57:in `/^(?:|I )follow
"([^"]*)"$/'
features/hidden_links.feature:30:in `When I follow "TextMate 2"'
Then I should not see the "Delete Project" link #
features/hidden_links.feature:31
Undefined step: "I should not see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:31:in `Then I should not see the
"Delete Project" link'
Scenario: Delete project link is hidden for signed-in users #
features/hidden_links.feature:33
Given I am signed in as "user@ticketee.com" #
features/hidden_links.feature:34
Undefined step: "I am signed in as "user@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:34:in `Given I am signed in as
"user@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should not see the "Delete Project" link #
features/hidden_links.feature:36
Undefined step: "I should not see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:36:in `Then I should not see the
"Delete Project" link'
Scenario: Delete project link is shown to admins #
features/hidden_links.feature:38
Given I am signed in as "admin@ticketee.com" #
features/hidden_links.feature:39
Undefined step: "I am signed in as "admin@ticketee.com""
(Cucumber::Undefined)
features/hidden_links.feature:39:in `Given I am signed in as
"admin@ticketee.com"'
When I follow "TextMate 2" #
features/step_definitions/web_steps.rb:56
Then I should see the "Delete Project" link #
features/hidden_links.feature:41
Undefined step: "I should see the "Delete Project" link"
(Cucumber::Undefined)
features/hidden_links.feature:41:in `Then I should see the "Delete
Project" link'
Failing Scenarios:
cucumber features/hidden_links.feature:13 # Scenario: Edit project link is
hidden for non-signed-in users
cucumber features/hidden_links.feature:28 # Scenario: Delete project link
is hidden for non-signed-in users
6 scenarios (2 failed, 4 undefined)
30 steps (2 failed, 4 skipped, 10 undefined, 14 passed)
0m0.748s
You can implement step definitions for undefined steps with these snippets:
Then(/^I should not see the "(.*?)" link$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Given(/^I am signed in as "(.*?)"$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Then(/^I should see the "(.*?)" link$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
and that is the show.html.erb where i have admins_only:
<% title(@project.name, "Projects") %>
<h2><%= @project.name %></h2>
<% admins_only do %>
<%= link_to "Edit Project", edit_project_path(@project) %>
<%= link_to "Delete Project", @project, :method => :delete, :confirm =>
"Are you sure you want to delete this project?" %>
<% end %>
<%= link_to "New Ticket", new_project_ticket_path(@project) %>
<ul id= 'tickets'>
<% @project.tickets.each do |ticket| %>
<li>
#<%= ticket.id %> - <%= link_to ticket.title, [@project, ticket] %>
</li>
<% end %>
</ul>
thats what i have tried but failed to solve my problem so help appreciated...
Two simultaneous generator functions, Python
Two simultaneous generator functions, Python
I have two functions:
def a():
while True:
yield stuff
def b():
while True:
yield otherstuff
and I want to have a loop which collects one yield from each function
stored in a for a() and b for b() ; for example. If I nest the for loops
which call them, it restarts the 2nd generator every-time the first loop
loops. Can I have any help with this?
Thanks!
I have two functions:
def a():
while True:
yield stuff
def b():
while True:
yield otherstuff
and I want to have a loop which collects one yield from each function
stored in a for a() and b for b() ; for example. If I nest the for loops
which call them, it restarts the 2nd generator every-time the first loop
loops. Can I have any help with this?
Thanks!
Subscribe to:
Comments (Atom)