I have accustomed to using Cucumber with Ruby on Rails for Behavior Driven Development when using sql database backends. What if data was stored within LDAP? I researched this point and it was very easy.
I assume that you have installed Ubuntu 10.04 (Lucid) and have configured the OpenLDAP server with the following instructions (Server setup): Setting up OpenLDAP on Ubuntu 10.04 Alpha 2 (Lucid)
We have to add some access rules to slapd configurations so that ActiveLdap will work. This is not necessarily the right way to do this but with these simple changes we can make ActiveLdap work. Don't do this to the production server if you don't know what it means.
modify_acls.ldif:Now we can start to make preparations for the new Rails project. In this example I use Ubuntu 10.04 Alpha 3 (Lucid)
Install the following packages from Ubuntu repositories:The following gems are needed: Add the gem binaries to PATH: Create new rails project: As the next step, generate new REST resources with scaffold. This command also performs database migration. This is good because then we can verify that the Cucumber step passed correctly in the typical use case (using an sqlite database). We use the posixAccount objectClass (LDAP) attribute name. Thus we don't have to rename the attribute as we introduce ActiveLdap. Create tables to the test database: Cucumber initialization: Generate User feature: Edit manage_users.feature file and replace the following content:
Scenario: Add new user
Given I am on the new user page
When I fill in "Cn" with "Joe Taylor" And I fill in "Uid" with "joe" And I fill in "Uidnumber" with "11001" And I fill in "Gidnumber" with "11001" And I fill in "Homedirectory" with "/home/joe" And I press "Create" Then I should see "Joe Taylor" And I should see "joe" And I should see "11001" And I should see "11001" And I should see "/home/joe" Now you can run Cucumber
Now we have User resource and we can test that it works. Data was stored in the sqlite database and in the next step we switch to ActiveLdap and LDAP storage.
Add following line to config/environment.rb:Initialize ActiveLdap: Edit config/ldap.yml file and add the following content: Modify app/models/user.rb file and replace it with the following content: OpenLDAP does not support a transaction system such as in a typical SQL-database. This is why we need use Before hook. First we have to clear the data so that the test scenario works correctly.
Edit features/step_definitions/user_steps.rb file and add following content:It should now work. Run cucumber command: ..and the result should be one passed scenario.
Add the following LDAP specific scenario. Edit features/manage_users.feature file and add the following content:DN duplicates are not allowed on the LDAP-server. This scenario ensures that the LDAP-server behaves like this.
Run cucumber command.
Result should be following:Jouni Korhonen