# Stories, permissions, authorization rules etc

**URL:** <https://www.ruby-forum.com/t/stories-permissions-authorization-rules-etc/155188>\
**Category:** RSpec\
**Created:** [December 9, 2008, 5:30am UTC](https://www.ruby-forum.com/t/stories-permissions-authorization-rules-etc/155188 "2008-12-09T05:30:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alberto\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e99b99/32.png) [@Alberto\_P](https://www.ruby-forum.com/u/Alberto_P)\
**Post date:** [December 9, 2008, 5:30am UTC](https://www.ruby-forum.com/t/stories-permissions-authorization-rules-etc/155188/1 "2008-12-09T05:30:43Z")

</div>

Hi,

my team and i have come to the point where we have defined a whole  
bunch of stories for an application.  
Almost all of the actions (besides login, etc.) should _not_ be  
accesible if not logged in.  
Almost all of the actions require a specific user role.

So, my question is. How do you put that in stories?  
I have come up with these different options:

1. In each story, e.g. ‘Add a new issue’, ‘Comment issue’, etc. you  
define a few extra scenarios more or less like this:

Scenario: Permission denied if not logged in  
Given i am not logged in  
When i visit ‘issues/new’  
I should see Permission denied  
And i should not see ‘Add Issue’

Scenario: Permission denied if role not developer  
Given i am logged in  
And my role is not developer  
When i visit ‘issues/new’  
I should see Permission denied  
And i should not see ‘Add Issue’

…

1. You could write a separate story (or multiple separate stories)  
just for the matter of describing permissions and authorizarion rules.

2. You could just write scenarios for the role requirements (like 1)  
and leave the logged\_in scenario out, giving for granted that you are  
going to make all actions inaccesible without logging in.

I prefer option 1 although it feels not DRY. I think explicit stories  
are good, and such important things as permissions etc. should not be  
left out. My mates argue that there has to be a better solutions than  
taking 50 stories and adding 2 o 3 scenarios that look more or less  
the same to each of them.

I don’t like 2 because it breaks the granularity of the stories.  
Stories should be more or less independant from each other. If you  
decide not to implement a specific story then you would have to edit  
again the permissions story. Also the permissions story will not pass  
until you have implemented all the scenarios = until you have  
implemented all the actions involved.

I don’t like 3 because it is against testing philosophy.You should not  
rely on the memory of humans. That’s one of the reasons to write  
stories. Theoretically you could write something like a scenario that  
goes through all your app routes and checks if they are accessible.

So tell me.  
How do you do such things?  
Do you have any other approaches?  
It’s important to us from a cucumber/rspec perspective (how do you  
test it?) but also from a requirements perspective (where do you write  
down that part when gathering the user stories?).

Cheers!  
Alberto.

---

<div class="post-metadata">

**Author:** ![Alberto\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e99b99/32.png) [@Alberto\_P](https://www.ruby-forum.com/u/Alberto_P)\
**Post date:** [December 9, 2008, 9:13am UTC](https://www.ruby-forum.com/t/stories-permissions-authorization-rules-etc/155188/2 "2008-12-09T09:13:41Z")

</div>

I usually assume my scenario user has been Given permission

and instead, I do the authorization testing in the controller specs  
with shared behaviors, for example,  
it\_should\_behave\_like “a login required action”  
it\_should\_behave\_like “a manager authorized action”

That said, I also might have a story where a user with the wrong  
permissions pokes around, but this is not a full coverage test at  
all. Its more for verifying how the app responds, with redirects or a  
message to the user, login prompt, etc.

–linoj

---

<div class="post-metadata">

**Author:** ![Alberto\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e99b99/32.png) [@Alberto\_P](https://www.ruby-forum.com/u/Alberto_P)\
**Post date:** [December 9, 2008, 9:52am UTC](https://www.ruby-forum.com/t/stories-permissions-authorization-rules-etc/155188/3 "2008-12-09T09:52:59Z")

</div>

You can improve the features you’ve given by

1. use named routes not url’s

2. not checking for not seeing specific things

3. A combined step with a more examples table  
Given I am logged in as a developer

4. having a general policy for what happens when access fails and  
testing  
that e.g. routing back to home page or where you came from

5. An uber combined step with a funky step matcher where the step  
definition  
would go through all the Roles and visit x with each one testing for an  
error  
Given I am not a logged in developer I should get an error when I  
visit x

‘5’ seems pretty ugly to me, but maybe in this case its bearable.

Making the features as simple as possible should reduce the resistance  
to  
their repitition

As to the issue of using stories for coverage, I guess a balance has to  
be  
struck which is very dependent on business needs. If there are specific  
business rules that need to be enforced for a role then make that  
explicit  
in features. If the business rule is much more general and their are  
lots of  
role/access combinations then maybe do this in a more unit test way i.e.  
not  
in features

2008/12/9 Alberto P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Alberto\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e99b99/32.png) [@Alberto\_P](https://www.ruby-forum.com/u/Alberto_P)\
**Post date:** [December 11, 2008, 5:32am UTC](https://www.ruby-forum.com/t/stories-permissions-authorization-rules-etc/155188/4 "2008-12-11T05:32:42Z")

</div>

On Tue, Dec 9, 2008 at 3:52 AM, Andrew P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> You can improve the features you’ve given by
> 
> 1. use named routes not url’s
> 2. not checking for not seeing specific things
> 3. A combined step with a more examples table  
> Given I am logged in as a developer

#3 is what I do. It works great,

> > So, my question is. How do you put that in stories?
> > 
> > just for the matter of describing permissions and authorizarion rules.
> > 
> > goes through all your app routes and checks if they are accessible.
> > 
> > * * *
> > 
> > rspec-users mailing list  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)
> 
> * * *
> 
> rspec-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)

–  
Zach D.  
[http://www.continuousthinking.com](http://www.continuousthinking.com)

> **[Homepage | Mutually Human](https://www.mutuallyhuman.com)**
>
> We empower businesses to overcome challenges with a holistic focus on People, Process, and Technology for lasting results and innovation.
