worked on tests

git-svn-id: https://dev.finn.de/svn/cockpit/trunk@728 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
t.felgentreff 15 years ago
parent 3e160ba807
commit a8acdd149c
  1. 26
      features/cost_reports.feature
  2. 132
      features/step_definitions/cost_steps.rb
  3. 19
      features/view_own_rates.feature
  4. 10
      test/exemplars/cost_entry_exemplar.rb
  5. 2
      test/exemplars/cost_object_exemplar.rb
  6. 4
      test/exemplars/cost_rate_exemplar.rb

@ -2,20 +2,20 @@ Feature: Cost Reports
Scenario: Anonymous user sees no costs
Given I am not logged in
And there is one Project with the following:
And there is 1 Project with the following:
| Name | Test |
And there is one cost entry
And there is 1 cost entry
And I am on the Cost Reports page for the project called Test
Then I should see "Login:"
And I should see "Password:"
Scenario: Admin user sees everything
Given I am admin
And there is only one project with the following:
And there is only 1 project with the following:
| Name | Test |
And there is one cost type with the following:
And there is 1 cost type with the following:
| name | Translation |
And there is one cost entry with the following:
And there is 1 cost entry with the following:
| units | 4242 |
And I am on the Cost Reports page for the project called Test
Then I should not see "No data to display"
@ -24,18 +24,18 @@ Feature: Cost Reports
Scenario: User who can see own costs, ONLY sees own costs
Given I am not logged in
And there is only one project with the following:
And there is only 1 project with the following:
| Name | Test |
And there is one User with the following:
And there is 1 User with:
| Login | bob |
| Firstname | Bob |
| Lastname | Bobbit |
And the user "Bob" is a "Developer" in the project "Test"
And the user "bob" is a "Developer" in the project "Test"
And the role "Developer" may have the following rights:
| View own cost entries |
And there is only one cost type with the following:
And there is only 1 cost type with the following:
| name | Translation |
And the user with login "Bob" has one cost entry
And the user "bob" has one cost entry
And there is 1 cost type with the following:
| name | Hidden Costs |
And the project "Test" has 2 cost entries with the following:
@ -51,9 +51,9 @@ Feature: Cost Reports
Scenario: User who can see own time entries, ONLY sees own time entries
Given I am not logged in
And there is only one project with the following:
And there is only 1 project with the following:
| Name | Test |
And there is one User with the following:
And there is only 1 User with:
| Login | bob |
| Firstname | Bob |
| Lastname | Bobbit |
@ -61,7 +61,7 @@ Feature: Cost Reports
And the user "Bob" is a "Developer" in the project "Test"
And the role "Developer" may have the following rights:
| View own time entries |
And the user with login "Bob" has one time entry
And the user with login "Bob" has 1 time entry
And the project with name "Test" has 2 time entries with the following:
| hours | 11 |
And I am logged in as "bob"

@ -6,37 +6,84 @@ Given /^I am(?: a)? "([^\"]*)"$/ do |login_or_role|
}
end
# If the current user is not already a member of the project, add him with his
# If the named or current user is not already a member of the project, add him with his
# primary role
Given /^I am a member of "([^\"]+)"$/ do |projectname|
Given /^(?:the user "([^\"]+)" is|I am)(?: a)? member of "([^\"]+)"$/ do |username, projectname|
p = Project.find_by_name(projectname)
unless p.members.detect {|m| m.user == User.current}
user = username ? User.find_by_login(username) : User.current
unless p.members.detect {|m| m.user == user}
steps %Q{
The user #{User.current.login} is a "#{User.current.roles.first.name}" in project "#{projectname}"
The user #{user.login} is a "#{user.roles.first.name}" in project "#{projectname}"
}
end
end
Given /^(?:the user "([^\"]+)" is|I am)(?: a)? member of "([^\"]+)":$/ do |username, projectname, table|
steps %Q{
The user #{user.login} is a "#{user.roles.first.name}" in project "#{projectname}"
}
user = username ? User.find_by_login(username) : User.current
p = Project.find_by_name(projectname)
if tables[/[hH]ourly [rR]ate/]
hr = HourlyRate.new.tap do |r|
r.project = p
r.user = user
r.valid_from = 1.year.ago
r.rate = tables[/[hH]ourly [rR]ate/][1].to_i
r.save!
end
end
end
# Add a "material" cost entry (which is just our standard cost entry) or a time entry to the last issue
Given /^(?:this issue|the issue "([^\"]+)") has (\d+) (?:([Tt]ime)|(?:(?:[Mm]aterial\s?)?[cC]ost))\s?[eE]?ntry with the following:$/ do |time, type, count|
owner = subject ? Issue.find_by_subject(subject) : Issue.last
klass = time ? TimeEntry : CostEntry
count.times do
ce = klass.spawn
table.rows_hash.each do |key, value|
if key =~ /[uU]ser/
ce.user = value =~ /me|I|myself/ ? User.current : User.find_by_login(value)
elsif key =~ /[cC]ost\s?[tT]ype/
ce.cost_type = CostType.find_by_name(value)
else
ce.send(:"#{key}=", value)
end
end
ce.project = owner.project
ce.save!
owner.cost_entries << ce
end
end
# Possibly add the current user to the project and set his hourly rate
Given /^I am a member of "([^\"]+)":$/ do |projectname, fields|
Given /^I am(?: a)? member of "([^\"]+)":$/ do |projectname, fields|
steps %Q{
Given I am a member of "#{projectname}"
}
fields.rows_hash.each do |key, value|
if key.gsub(" ", "_").underscore == "hourly_rate"
HourlyRate.create! :rate => value,
HourlyRate.create! :rate => value,
:user => User.find(5),
:project => Project.first,
:valid_from => Date.today)
:project => Project.first,
:valid_from => Date.today
end
end
end
Given /^the (?:project|Project)(?: named| with(?: the)? name| called)? "([^\"]*)" has (only )?(\d+|[a-z]+) [cC]ost\s?[eE]ntr(?:y|ies) with the following:$/ do |name, do_delete_all, count, table|
Given /^the (?:([Uu]ser)|([Pp]roject))(?: named| with(?: the)? name| called)? "([^\"]*)" has (only )?(\d+|[a-z]+) [cC]ost\s?[eE]ntr(?:y|ies)$/ do |user, project, name, do_delete_all, count|
steps %Q{
Given the #{"user" if user}#{"project" if project} "#{name}" has #{"only " if do_delete_all}#{count} cost entries with the following:
| |
}
end
Given /^the (?:([Uu]ser)|([Pp]roject))(?: named| with(?: the)? name| called)? "([^\"]*)" has (only )?(\d+|[a-z]+) [cC]ost\s?[eE]ntr(?:y|ies) with the following:$/ do |user, project, name, do_delete_all, count, table|
count = 1 if count == "one"
count = (count || 1).to_i
p = Project.find_by_name(name)
u = user ? User.find_by_login(name) : u = User.find_by_login("admin")
p = project ? Project.find_by_name(name) : u.members.last.project
if do_delete_all
CostEntry.find(:all, :conditions => ["project_id = #{p.id}"]).each do |c|
@ -44,20 +91,22 @@ Given /^the (?:project|Project)(?: named| with(?: the)? name| called)? "([^\"]*)
end
end
count.times do
CostEntry.spawn.tap do |i|
i.project = p
i.issue = Issue.generate_for_project!(p)
unless table.raw.first.first.blank? # if we get an empty table, ignore that
table.rows_hash.each do |field,value|
field = field.gsub(" ", "_").underscore.to_sym
old_val = i.send(field)
i.send(:"#{field}=", value)
i.send(:"#{field}=", old_val) unless i.save
count.times do
as_admin do
CostEntry.spawn.tap do |i|
i.project = p
i.issue = Issue.generate_for_project!(p)
i.user = u
unless table.raw.first.first.blank? # if we get an empty table, ignore that
table.rows_hash.each do |field,value|
field = field.gsub(" ", "_").underscore.to_sym
old_val = i.send(field)
i.send(:"#{field}=", value)
i.send(:"#{field}=", old_val) unless i.save
end
end
end
end.save!
end.save!
end
end
end
@ -68,19 +117,48 @@ Given /^the (?:project|Project)(?: named| with(?: the)? name| called)? "([^\"]*)
}
end
Given /^there (?:is|are)( only)? (\d+) [Uu]ser[s]? with:$/ do |do_delete_all, count, fields|
rate_regex = /[dD]efault\s?[rR]ate/
new_table = fields.reject_key(rate_regex)
if do_delete_all
admin = User.find_by_login("admin")
anonymous = AnonymousUser.first
User.delete_all
admin.save!
anonymous.save!
end
users = create_some_objects(count, false, "User", new_table)
users.each do |u|
u.hashed_password = User.hash_password("admin")
unless new_table.raw.length == fields.raw.length
fields.rows_hash.each do |k,v|
if k =~ rate_regex
rate = DefaultHourlyRate.new.tap do |r|
r.valid_from = Date.today
r.rate = v
r.user = u
end
rate.save!
end
end
end
u.save!
end
end
Given /^there is a standard cost control project named "([^\"]*)"$/ do |name|
steps %Q{
Given there is one project with the following:
| Name | #{name} |
And the project "#{name}" has 1 subproject
And the role "Manager" may have the following rights:
| |
| View own cost entries |
And the role "Controller" may have the following rights:
| |
| View own cost entries |
And the role "Developer" may have the following rights:
| |
| View own cost entries |
And the role "Reporter" may have the following rights:
| |
| Create issues |
And the role "Supplier" may have the following rights:
| View own hourly rate |
| View own cost entries |

@ -2,29 +2,30 @@ Feature: Permission View Own hourly and cost rates
Scenario: Users that by set permission are only allowed to see their own rates, can not see the rates of others.
Given there is a standard cost control project named "Standard Project"
And I am "Supplier" # I am allowed to see my own hourly and cost rates.
And I am "Supplier"
# I am allowed to see my own hourly and cost rates.
And I am member of "Standard Project":
| hourly rate | 10.00 |
And the project with name "Standard Project" has 1 issue with the following:
| subject | "test_issue" |
And this issue has one time entry with the following:
And this issue has 1 time entry with the following:
| hours | 1.00 |
| user | me |
And this issue has one material cost entry with the following:
And this issue has 1 material cost entry with the following:
| units | 2.00 |
| user | me |
| cost type | Translation |
# One translation costs 7.00 €
And "Manager" is member of "Standard Project":
And the user "manager" is member of "Standard Project":
| hourly rate | 11.00 |
And "test_issue" has time entry:
And the issue "test_issue" has 1 time entry with the following:
| hours | 3.00 |
| user | Manager |
And "test_issue" has cost entry:
And the issue "test_issue" has 1 cost entry with the following:
| units | 5.00 |
| user | Manager |
| cost type | Translation |
And I am on the Issue page for the issue test_issue
And I am on the page for the issue "test_issue"
Then I should see "1.00 h"
And I should see "2.00 Translations"
And I should see "10.00 "
@ -33,8 +34,8 @@ Feature: Permission View Own hourly and cost rates
And I should not see "35.00 " # material costs only of Manager
And I should not see "43.00 " # labour costs of me and Manager
And I should not see "49.00 " # material costs of me and Manager
And then I go to issues page
And I select to see column "labour costs"
And I am on the issues page for the project called "Standard Project"
And I select to see column "labour costs"
Then I should see "1.00 h"
And I should see "2.00 Translations"
And I should see "24.00 "

@ -16,22 +16,22 @@ CostEntry.class_eval do
generator_for :tweek, 10
def self.next_project
Project.last || Project.generate!
Project.last or Project.generate!
end
def self.next_cost_rate
CostRate.generate!
CostRate.last or CostRate.generate!
end
def self.next_user
User.generate_with_protected!
User.find_by_login("admin")
end
def self.next_cost_type
CostType.last || CostType.generate!
CostType.last or CostType.generate!
end
def self.next_issue
self.next_project.issues.last || Issue.generate_for_project!(next_project)
self.next_project.issues.last or Issue.generate_for_project!(next_project)
end
end

@ -10,6 +10,6 @@ CostObject.class_eval do
end
def self.next_author
User.first
User.find_by_name("admin")
end
end

@ -1,10 +1,10 @@
Rate.class_eval do
CostRate.class_eval do
generator_for :valid_from, :method => :next_valid_from
generator_for :rate, 10
generator_for :cost_type, :method => :next_cost_type
def self.next_cost_type
CostType.last || CostType.generate!
CostType.last or CostType.generate!
end
def self.next_valid_from

Loading…
Cancel
Save