Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
caa09e69
Commit
caa09e69
authored
May 05, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add License unit test.
parent
e7154898
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
174 additions
and
7 deletions
+174
-7
app/models/license.rb
app/models/license.rb
+0
-7
spec/models/license_spec.rb
spec/models/license_spec.rb
+174
-0
No files found.
app/models/license.rb
View file @
caa09e69
...
@@ -79,13 +79,6 @@ class License < ActiveRecord::Base
...
@@ -79,13 +79,6 @@ class License < ActiveRecord::Base
else
else
super
super
end
end
(
license
&&
license
.
respond_to?
(
method_name
))
||
super
end
def
active_user_restriction_exceeded?
return
false
unless
self
.
restricted?
(
:active_user_count
)
User
.
active
.
count
>
self
.
restrictions
[
:active_user_count
]
end
end
private
private
...
...
spec/models/license_spec.rb
0 → 100644
View file @
caa09e69
require
"spec_helper"
describe
License
do
let
(
:gl_license
)
{
Gitlab
::
License
.
new
(
issued_at:
Date
.
today
,
licensee:
{
"Name"
=>
"GitLab Test Env"
})
}
let
(
:license
)
{
License
.
new
(
data:
gl_license
.
export
)
}
describe
"Validation"
do
describe
"Valid license"
do
context
"when the license is provided"
do
it
"is valid"
do
expect
(
license
).
to
be_valid
end
end
context
"when no license is provided"
do
before
do
license
.
data
=
nil
end
it
"is invalid"
do
expect
(
license
).
to_not
be_valid
end
end
end
describe
"Active user count"
do
context
"when there is no active user count restriction"
do
it
"is valid"
do
expect
(
license
).
to
be_valid
end
end
context
"when the active user count restriction is exceeded"
do
before
do
gl_license
.
restrictions
=
{
active_user_count:
User
.
active
.
count
-
1
}
end
it
"is invalid"
do
expect
(
license
).
to_not
be_valid
end
end
context
"when the active user count restriction is not exceeded"
do
before
do
gl_license
.
restrictions
=
{
active_user_count:
User
.
active
.
count
+
1
}
end
it
"is valid"
do
expect
(
license
).
to
be_valid
end
end
end
describe
"Not expired"
do
context
"when the license doesn't expire"
do
it
"is valid"
do
expect
(
license
).
to
be_valid
end
end
context
"when the license has expired"
do
before
do
gl_license
.
expires_at
=
Date
.
yesterday
end
it
"is valid"
do
expect
(
license
).
to_not
be_valid
end
end
context
"when the license has yet to expire"
do
before
do
gl_license
.
expires_at
=
Date
.
tomorrow
end
it
"is valid"
do
expect
(
license
).
to
be_valid
end
end
end
end
describe
"Class methods"
do
let!
(
:license
)
{
License
.
last
}
before
do
License
.
reset_current
allow
(
License
).
to
receive
(
:last
).
and_return
(
license
)
end
describe
".current"
do
context
"when there is no license"
do
let!
(
:license
)
{
nil
}
it
"returns nil"
do
expect
(
License
.
current
).
to
be_nil
end
end
context
"when the license is invalid"
do
before
do
allow
(
license
).
to
receive
(
:valid?
).
and_return
(
false
)
end
it
"returns nil"
do
expect
(
License
.
current
).
to
be_nil
end
end
context
"when the license is valid"
do
it
"returns the license"
do
expect
(
License
.
current
)
end
end
end
describe
".block_changes?"
do
context
"when there is no current license"
do
before
do
allow
(
License
).
to
receive
(
:current
).
and_return
(
nil
)
end
it
"returns true"
do
expect
(
License
.
block_changes?
).
to
be_truthy
end
end
context
"when the current license is set to block changes"
do
before
do
allow
(
license
).
to
receive
(
:block_changes?
).
and_return
(
true
)
end
it
"returns true"
do
expect
(
License
.
block_changes?
).
to
be_truthy
end
end
context
"when the current license doesn't block changes"
do
it
"returns false"
do
expect
(
License
.
block_changes?
).
to
be_falsey
end
end
end
end
describe
"#license"
do
context
"when no data is provided"
do
before
do
license
.
data
=
nil
end
it
"returns nil"
do
expect
(
license
.
license
).
to
be_nil
end
end
context
"when corrupt license data is provided"
do
before
do
license
.
data
=
"whatever"
end
it
"returns nil"
do
expect
(
license
.
license
).
to
be_nil
end
end
context
"when valid license data is provided"
do
it
"returns the license"
do
expect
(
license
.
license
).
to_not
be_nil
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment