Skip to content

Commit 8136a3a

Browse files
committed
security system
0 parents  commit 8136a3a

File tree

8 files changed

+214
-0
lines changed

8 files changed

+214
-0
lines changed

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--colour
2+
--format documentation

Rakefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'rubygems'
2+
require 'rspec/core/rake_task'
3+
4+
RSpec::Core::RakeTask.new(:spec) do |t|
5+
t.spec_opts = ['--colour', '--format documentation']
6+
end
7+
8+
desc "Default build will run specs"
9+
task :default => :spec

lib/security.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
class User
2+
3+
attr_reader :permission
4+
5+
def initialize(params={})
6+
@access = params[:access]
7+
@permission = params[:permission]
8+
end
9+
10+
def has_access?
11+
SecurityLogger.log_event(:name=>"blah")
12+
@access
13+
end
14+
15+
16+
end
17+
18+
class SecurityLogger
19+
20+
def initialize()
21+
22+
end
23+
24+
def self.log_event(args={})
25+
@event = args[:access]
26+
end
27+
28+
29+
end
30+
31+
module Security
32+
class Elevator
33+
attr_reader :locked
34+
35+
def self.validate(user, current_time)
36+
return true if current_time=="business hours"
37+
user.permission
38+
end
39+
end
40+
41+
class Alarm
42+
43+
44+
def self.lockdown
45+
end
46+
end
47+
end
48+

spec/security_spec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'spec_helper'
2+
3+
describe Security do
4+
end

spec/security_spec.rb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
require 'spec_helper'
2+
3+
describe 'Security' do
4+
5+
context 'Facility access requests' do
6+
before do
7+
@current_time = 'late'
8+
SecurityLogger.should_receive(:log_event)
9+
end
10+
11+
context 'for a user with access' do
12+
before do
13+
@user = User.new(:access => true)
14+
end
15+
16+
it 'should grant user access level' do
17+
@user.should have_access
18+
end
19+
end
20+
21+
context 'for a user without access' do
22+
before do
23+
@user = User.new(:access => false)
24+
end
25+
it 'should not grant acess' do
26+
@user.should_not have_access
27+
end
28+
end
29+
30+
31+
end
32+
33+
context 'Elevator Access' do
34+
35+
context 'when it is late' do
36+
37+
before do
38+
@current_time = 'not business hours'
39+
@user_with_permission = User.new(:permission => true)
40+
@user_without_permission = User.new(:permission => false)
41+
end
42+
43+
it 'should validate access level to user with permission'do
44+
validated = Security::Elevator.validate(@user_with_permission, @current_time)
45+
validated.should == true
46+
end
47+
48+
it 'should not validate access level'do
49+
validated = Security::Elevator.validate(@user_without_permission, @current_time)
50+
validated.should == false
51+
end
52+
end
53+
54+
context 'when it\'s not late' do
55+
56+
before do
57+
@current_time = 'business hours'
58+
@user_with_permission = User.new(:permission => true)
59+
@user_without_permission = User.new(:permission => false)
60+
end
61+
62+
it 'should grant full elevator access' do
63+
validated = Security::Elevator.validate(@user_without_permission,@current_time)
64+
validated.should == true
65+
validated =Security::Elevator.validate(@user_with_permission,@current_time)
66+
67+
validated.should == true
68+
end
69+
end
70+
end
71+
72+
context 'Office Access' do
73+
before do
74+
end
75+
it 'should validate employee acess'
76+
end
77+
78+
context 'Lockdown Mode' do
79+
before do
80+
Security::Elevator.locked = true
81+
end
82+
83+
it 'Should Secure all Elevators' do
84+
Security::Elevator.locked.should == true
85+
end
86+
end
87+
88+
end

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require File.expand_path('lib/security')

spec/stories.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Title Building Alarm System
2+
3+
Narrative:
4+
As a alarm
5+
I want to secure the building
6+
So that shit doesn't get stolen
7+
8+
9+
//Acceptance Criteria: The building is secure
10+
11+
Scenario 1: Building Access Requested
12+
Given that it is after business hours
13+
When Front door panel is a access is requested
14+
Then validate user access level
15+
And grant access accordingly
16+
And log request
17+
18+
Scenario 2: Elevator Access
19+
Given that it is after business hours
20+
When Elevator access is requested
21+
Then validate access level
22+
And grant access accordingly
23+
And log request
24+
25+
Scenario 3: Office office
26+
Given office is locked
27+
When employee requests office access
28+
Then valid employee access level
29+
And grant access accordingly
30+
And log access request
31+
32+
Scenario 4: Lock mode
33+
Given lockdown mode is activated
34+
When lockdown mode is activated
35+
Then secure all elevators
36+
Then Alert authorities
37+
Then Lockdown rooms
38+
Activate visual notifications
39+
Activate audible notifications
40+
And authorities are alerted
41+
And log event
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
Scenario 4: Secure secure areas
54+
Given alarm is armed
55+
And and it is after hours
56+
When motion is detected in secure areas
57+
Then alarm is activated
58+
And authorities are alerted
59+
And log request

watchr.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
watch(/\.rb$/) do |file|
2+
system('clear && rspec spec/security_spec.rb')
3+
end

0 commit comments

Comments
 (0)