model_citizen 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4dbedf18cde1a51229bc07787b9f8d3a31834828
4
+ data.tar.gz: effa351e539c1201a2298f8a88801816d5b2426c
5
+ SHA512:
6
+ metadata.gz: b8c04776ed0b93e1739e55f97335a113c23701d5312aa8e32cb3d32a5860b4ca971b2595ded3bbd19e2cc9b97fbaedf29b1ded93fcabcb76c95c5485230f5d1c
7
+ data.tar.gz: e768bb1b3ed02ca7d58bfc851fee96abbda32c12c9ad2cc49434b051fe1b6717970ab8c113b21bd3b292ec8d41ce63878bc21bae4df2acdad3ee1daf2d7c86f5
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sylwia Olak
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # ModelCitizen
2
+
3
+ Provides validation methods to LumberYard Sinatra app and LumberYard command line app models.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'model_citizen'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install model_citizen
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it ( https://github.com/[my-github-username]/model_citizen/fork )
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
8
+
@@ -0,0 +1,25 @@
1
+ module ModelCitizen
2
+ class Messages
3
+
4
+ attr_reader :messages
5
+
6
+ def initialize
7
+ @messages = {"username_prompt" => "Please enter your username.",
8
+ "choose_action" => "Please select what you'd like to do." ,
9
+ "invalid_choice" => "That is not a valid choice, please try again.",
10
+ "enter_employee_first" => "Please enter employee first name.",
11
+ "enter_employee_last" => "Please enter employee last name.",
12
+ "enter_employee_username" => "Please enter employee username.",
13
+ "enter_employee_type" => "Please enter employee type (admin or non-admin).",
14
+ "enter_client_name" => "Please enter client name.",
15
+ "enter_client_type" => "Please enter client type (if regular client, please enter 'standard').",
16
+ "enter_date" => "Please input the project date using this format : YYYY/MM/DD",
17
+ "future_date_error" => "You cannot log time for the future, please select a different date.",
18
+ "enter_hours" => "Please input hours worked"}
19
+ end
20
+
21
+ def get_message(message_choice)
22
+ @messages.fetch(message_choice)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ require 'date'
2
+ module ModelCitizen
3
+ class Validations
4
+
5
+ def not_nil_or_empty?(attributes)
6
+ !attributes.include?(nil) && !attributes.include?("")
7
+ end
8
+
9
+ def value_included?(*value, attribute)
10
+ [*value].include? attribute
11
+ end
12
+
13
+ def valid_date?(date)
14
+ valid_string?(date) && past_date?(date)
15
+ end
16
+
17
+ def no_duplicates?(value, data_structure)
18
+ !data_structure.include? value
19
+ end
20
+
21
+ private
22
+
23
+ def valid_string?(date)
24
+ y, m, d = date.split '/'
25
+ return false if y.to_i == 0
26
+ Date.valid_date? y.to_i, m.to_i, d.to_i
27
+ end
28
+
29
+ def past_date?(date)
30
+ Date.parse(date) < Date.today
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module ModelCitizen
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'model_citizen/version'
2
+ require 'model_citizen/messages'
3
+ require 'model_citizen/validations'
4
+ require 'date'
5
+
6
+ module ModelCitizen
7
+ end
8
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'model_citizen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "model_citizen"
8
+ spec.version = ModelCitizen::VERSION
9
+ spec.authors = ["Sylwia Olak"]
10
+ spec.email = ["pumpkincouture@gmail.com"]
11
+ spec.summary = %q{Provides validation methods for models in the LumberYard Sinatra app and command line application.}
12
+ spec.homepage = "https://github.com/pumpkincouture/model_citizen"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "3.1.0"
23
+ end
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+
3
+ describe ModelCitizen::Messages do
4
+
5
+ context "displaying messages" do
6
+ it "should return a prompt to enter username" do
7
+ type_validator = ModelCitizen::Messages.new.get_message("username_prompt")
8
+ expect(type_validator).to eq("Please enter your username.")
9
+ end
10
+
11
+ it "should return a choose action message" do
12
+ type_validator = ModelCitizen::Messages.new.get_message("choose_action")
13
+ expect(type_validator).to eq("Please select what you'd like to do.")
14
+ end
15
+
16
+ it "should return an error message" do
17
+ type_validator = ModelCitizen::Messages.new.get_message("invalid_choice")
18
+ expect(type_validator).to eq("That is not a valid choice, please try again.")
19
+ end
20
+
21
+ it "should return a prompt to enter employee first name" do
22
+ type_validator = ModelCitizen::Messages.new.get_message("enter_employee_first")
23
+ expect(type_validator).to eq("Please enter employee first name.")
24
+ end
25
+
26
+ it "should return a prompt to enter employee last name" do
27
+ type_validator = ModelCitizen::Messages.new.get_message("enter_employee_last")
28
+ expect(type_validator).to eq("Please enter employee last name.")
29
+ end
30
+
31
+ it "should return a prompt tp enter employee username" do
32
+ type_validator = ModelCitizen::Messages.new.get_message("enter_employee_username")
33
+ expect(type_validator).to eq("Please enter employee username.")
34
+ end
35
+
36
+ it "should return a prompt to enter employee type" do
37
+ type_validator = ModelCitizen::Messages.new.get_message("enter_employee_type")
38
+ expect(type_validator).to eq("Please enter employee type (admin or non-admin).")
39
+ end
40
+
41
+ it "should return a prompt to enter client name" do
42
+ type_validator = ModelCitizen::Messages.new.get_message("enter_client_name")
43
+ expect(type_validator).to eq("Please enter client name.")
44
+ end
45
+
46
+ it "should return a prompt for client type" do
47
+ type_validator = ModelCitizen::Messages.new.get_message("enter_client_type")
48
+ expect(type_validator).to eq("Please enter client type (if regular client, please enter 'standard').")
49
+ end
50
+
51
+ it "should return a prompt to input the date" do
52
+ type_validator = ModelCitizen::Messages.new.get_message("enter_date")
53
+ expect(type_validator).to eq("Please input the project date using this format : YYYY/MM/DD")
54
+ end
55
+
56
+ it "should return an error for logging time in the future" do
57
+ type_validator = ModelCitizen::Messages.new.get_message("future_date_error")
58
+ expect(type_validator).to eq("You cannot log time for the future, please select a different date.")
59
+ end
60
+
61
+ it "should return a prompt for hours" do
62
+ type_validator = ModelCitizen::Messages.new.get_message("enter_hours")
63
+ expect(type_validator).to eq("Please input hours worked")
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe ModelCitizen do
4
+ end
@@ -0,0 +1,13 @@
1
+ require 'model_citizen/messages'
2
+ require 'model_citizen/validations'
3
+
4
+ RSpec.configure do |config|
5
+ config.failure_color = :red
6
+ config.success_color = :green
7
+ config.detail_color = :yellow
8
+ config.tty = true
9
+ config.color = true
10
+ config.formatter = :documentation
11
+ config.order = :rand
12
+ end
13
+
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe ModelCitizen::Validations do
4
+
5
+ context "checking attributes for nil or empty values" do
6
+ it "should return true if no attributes are nil or empty" do
7
+ first_name_validator = ModelCitizen::Validations.new.not_nil_or_empty?(["Sylwia", "Olak", "solak", "admin"])
8
+ expect(first_name_validator).to eq(true)
9
+ end
10
+
11
+ it "should return false if there are nil attributes" do
12
+ first_name_validator = ModelCitizen::Validations.new.not_nil_or_empty?(["Sylwia", "Olak", nil, "admin"])
13
+ expect(first_name_validator).to eq(false)
14
+ end
15
+
16
+ it "should return false if there are empty string attributes" do
17
+ first_name_validator = ModelCitizen::Validations.new.not_nil_or_empty?(["Sylwia", "Olak", "solak", ""])
18
+ expect(first_name_validator).to eq(false)
19
+ end
20
+
21
+ it "should return false if there are any nil or empty attributes" do
22
+ first_name_validator = ModelCitizen::Validations.new.not_nil_or_empty?([nil, "", "6", ""])
23
+ expect(first_name_validator).to eq(false)
24
+ end
25
+ end
26
+
27
+ context "validating whether or not attribute contains a value" do
28
+ it "should return true if selected attribute matches value argument" do
29
+ employee_type = "admin"
30
+ type_validator = ModelCitizen::Validations.new.value_included?("admin", "non-admin", employee_type)
31
+ expect(type_validator).to eq(true)
32
+ end
33
+
34
+ it "should return false if selected attribute does not match value argument" do
35
+ employee_type = "uncool"
36
+ type_validator = ModelCitizen::Validations.new.value_included?("admin", "cool", employee_type)
37
+ expect(type_validator).to eq(false)
38
+ end
39
+
40
+ it "should return false if attribute does not include value" do
41
+ employee_type = "non-admin"
42
+ type_validator = ModelCitizen::Validations.new.value_included?("admin", employee_type)
43
+ expect(type_validator).to eq(false)
44
+ end
45
+ end
46
+
47
+ context "validating date strings" do
48
+ it "should return true if date is valid" do
49
+ date = "2015/2/3"
50
+ type_validator = ModelCitizen::Validations.new.valid_date?(date)
51
+ expect(type_validator).to eq(true)
52
+ end
53
+
54
+ it "should return false if date is missing year" do
55
+ date = "/2/3"
56
+ type_validator = ModelCitizen::Validations.new.valid_date?(date)
57
+ expect(type_validator).to eq(false)
58
+ end
59
+
60
+ it "should return false if date is missing month" do
61
+ date = "2015//3"
62
+ type_validator = ModelCitizen::Validations.new.valid_date?(date)
63
+ expect(type_validator).to eq(false)
64
+ end
65
+
66
+ it "should return false if date is missing day" do
67
+ date = "2015/2/"
68
+ type_validator = ModelCitizen::Validations.new.valid_date?(date)
69
+ expect(type_validator).to eq(false)
70
+ end
71
+
72
+ it "should return true if date is not in the future" do
73
+ date = "2015/1/15"
74
+ type_validator = ModelCitizen::Validations.new.valid_date?(date)
75
+ expect(type_validator).to eq(true)
76
+ end
77
+
78
+ it "should return false if date is in the future" do
79
+ date = "2016/2/3"
80
+ type_validator = ModelCitizen::Validations.new.valid_date?(date)
81
+ expect(type_validator).to eq(false)
82
+ end
83
+ end
84
+
85
+ context "checking for duplicates" do
86
+ it "should return true if there are no duplicates" do
87
+ animals = ["cat", "dog", "parrot", "monkey", "ferret"]
88
+ type_validator = ModelCitizen::Validations.new.no_duplicates?("capybara", animals)
89
+ expect(type_validator).to eq(true)
90
+ end
91
+
92
+ it "should return false if there are duplicates" do
93
+ animals = ["cat", "dog", "parrot", "monkey", "ferret"]
94
+ type_validator = ModelCitizen::Validations.new.no_duplicates?("ferret", animals)
95
+ expect(type_validator).to eq(false)
96
+ end
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: model_citizen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Sylwia Olak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ description:
56
+ email:
57
+ - pumpkincouture@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/model_citizen.rb
68
+ - lib/model_citizen/messages.rb
69
+ - lib/model_citizen/validations.rb
70
+ - lib/model_citizen/version.rb
71
+ - model_citizen.gemspec
72
+ - spec/messages_spec.rb
73
+ - spec/model_citizen_spec.rb
74
+ - spec/spec_helper.rb
75
+ - spec/validations_spec.rb
76
+ homepage: https://github.com/pumpkincouture/model_citizen
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.5
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Provides validation methods for models in the LumberYard Sinatra app and
100
+ command line application.
101
+ test_files:
102
+ - spec/messages_spec.rb
103
+ - spec/model_citizen_spec.rb
104
+ - spec/spec_helper.rb
105
+ - spec/validations_spec.rb