Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 8 commits
  • 42 files changed
  • 0 commit comments
  • 1 contributor
Showing with 1,098 additions and 284 deletions.
  1. +1 −0 .rspec
  2. +1 −0 .rvmrc
  3. +19 −7 Gemfile
  4. +89 −2 Gemfile.lock
  5. +44 −0 app/admin/dashboards.rb
  6. +76 −0 app/admin/employees.rb
  7. +32 −0 app/admin/teams.rb
  8. +1 −0 app/assets/javascripts/active_admin.js
  9. +6 −0 app/assets/stylesheets/active_admin.css.scss
  10. +9 −0 app/models/admin_user.rb
  11. +14 −0 app/models/employee.rb
  12. +9 −0 app/models/team.rb
  13. +5 −0 app/models/team_employee.rb
  14. +0 −1 config/application.rb
  15. +0 −6 config/database.yml
  16. +1 −1 config/environments/production.rb
  17. +129 −0 config/initializers/active_admin.rb
  18. +223 −0 config/initializers/devise.rb
  19. +4 −0 config/initializers/twitter.rb
  20. +57 −0 config/locales/devise.en.yml
  21. +5 −1 config/routes.rb
  22. +17 −0 db/migrate/20120426114215_create_admin_notes.rb
  23. +25 −0 db/migrate/20120426114216_move_admin_notes_to_comments.rb
  24. +50 −0 db/migrate/20120426164157_devise_create_admin_users.rb
  25. +15 −0 db/migrate/20120426220345_create_employees.rb
  26. +10 −0 db/migrate/20120426220819_create_teams.rb
  27. +10 −0 db/migrate/20120426234935_create_team_employees.rb
  28. +5 −0 db/migrate/20120427043229_add_twitter_profile_picture_to_employees.rb
  29. +76 −0 db/schema.rb
  30. +0 −241 public/index.html
  31. +87 −0 spec/controllers/admin/employees_controller_spec.rb
  32. +10 −0 spec/factories/admin_users.rb
  33. +12 −0 spec/factories/employees.rb
  34. +6 −0 spec/factories/teams.rb
  35. +16 −0 spec/models/employee_spec.rb
  36. +34 −0 spec/spec_helper.rb
  37. 0 test/fixtures/.gitkeep
  38. 0 test/functional/.gitkeep
  39. 0 test/integration/.gitkeep
  40. +0 −12 test/performance/browsing_test.rb
  41. +0 −13 test/test_helper.rb
  42. 0 test/unit/.gitkeep
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm use 1.9.2@agent007 --create
View
26 Gemfile
@@ -5,17 +5,28 @@ gem 'rails', '3.1.3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
-gem 'sqlite3'
-
-
+gem 'formtastic', '2.1.1'
+gem 'activeadmin', '0.4.3'
+gem 'meta_search', '>= 1.1.0.pre'
+gem 'twitter', '2.2.2'
+gem 'pg'
+gem 'sass-rails', '~> 3.1.5'
+gem 'coffee-rails', '~> 3.1.1'
+gem 'uglifier', '>= 1.0.3'
# Gems used only for assets and not required
# in production environments by default.
-group :assets do
- gem 'sass-rails', '~> 3.1.5'
- gem 'coffee-rails', '~> 3.1.1'
- gem 'uglifier', '>= 1.0.3'
+group :development do
+ gem 'sqlite3'
+ gem 'rspec-rails', '2.9.0'
end
+group :development, :test do
+ gem 'factory_girl_rails', '1.3.0'
+end
+group :assets do
+end
+gem 'validate_url', '0.2.0'
+gem 'validate_email', '0.1.5'
gem 'jquery-rails'
# To use ActiveModel has_secure_password
@@ -32,5 +43,6 @@ gem 'jquery-rails'
group :test do
# Pretty printed test output
+ gem 'shoulda', '2.11.3'
gem 'turn', '0.8.2', :require => false
end
View
91 Gemfile.lock
@@ -15,6 +15,17 @@ GEM
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.3)
+ activeadmin (0.4.3)
+ bourbon (>= 1.0.0)
+ devise (>= 1.1.2)
+ fastercsv
+ formtastic (>= 2.0.0)
+ inherited_resources (> 0)
+ jquery-rails (>= 1.0.0)
+ kaminari (>= 0.13.0)
+ meta_search (>= 0.9.2)
+ rails (>= 3.0.0)
+ sass (>= 3.1.0)
activemodel (3.1.3)
activesupport (= 3.1.3)
builder (~> 3.0.0)
@@ -31,6 +42,9 @@ GEM
multi_json (~> 1.0)
ansi (1.4.2)
arel (2.2.3)
+ bcrypt-ruby (3.0.1)
+ bourbon (1.4.0)
+ sass (>= 3.1)
builder (3.0.0)
coffee-rails (3.1.1)
coffee-script (>= 2.2.0)
@@ -39,21 +53,55 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.3.1)
+ devise (2.0.4)
+ bcrypt-ruby (~> 3.0)
+ orm_adapter (~> 0.0.3)
+ railties (~> 3.1)
+ warden (~> 1.1.1)
+ diff-lcs (1.1.3)
erubis (2.7.0)
- execjs (1.3.0)
+ execjs (1.3.1)
multi_json (~> 1.0)
+ factory_girl (2.2.0)
+ activesupport
+ factory_girl_rails (1.3.0)
+ factory_girl (~> 2.2.0)
+ railties (>= 3.0.0)
+ faraday (0.8.0)
+ multipart-post (~> 1.1)
+ fastercsv (1.5.4)
+ formtastic (2.1.1)
+ actionpack (~> 3.0)
+ has_scope (0.5.1)
hike (1.2.1)
i18n (0.6.0)
+ inherited_resources (1.3.1)
+ has_scope (~> 0.5.0)
+ responders (~> 0.6)
jquery-rails (1.0.19)
railties (~> 3.0)
thor (~> 0.14)
json (1.6.6)
+ kaminari (0.13.0)
+ actionpack (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ railties (>= 3.0.0)
mail (2.3.3)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ meta_search (1.1.3)
+ actionpack (~> 3.1)
+ activerecord (~> 3.1)
+ activesupport (~> 3.1)
+ polyamorous (~> 0.5.0)
mime-types (1.18)
multi_json (1.3.2)
+ multipart-post (1.1.5)
+ orm_adapter (0.0.7)
+ pg (0.13.2)
+ polyamorous (0.5.0)
+ activerecord (~> 3.0)
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.2)
@@ -82,13 +130,30 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ responders (0.9.1)
+ railties (~> 3.1)
+ rspec (2.9.0)
+ rspec-core (~> 2.9.0)
+ rspec-expectations (~> 2.9.0)
+ rspec-mocks (~> 2.9.0)
+ rspec-core (2.9.0)
+ rspec-expectations (2.9.1)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.9.0)
+ rspec-rails (2.9.0)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.9.0)
sass (3.1.16)
sass-rails (3.1.6)
actionpack (~> 3.1.0)
railties (~> 3.1.0)
sass (>= 3.1.10)
tilt (~> 1.3.2)
- sprockets (2.0.3)
+ shoulda (2.11.3)
+ simple_oauth (0.1.7)
+ sprockets (2.0.4)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
@@ -100,19 +165,41 @@ GEM
polyglot (>= 0.3.1)
turn (0.8.2)
ansi (>= 1.2.2)
+ twitter (2.2.2)
+ activesupport (>= 2.3.9, < 4)
+ faraday (~> 0.7)
+ multi_json (~> 1.3)
+ simple_oauth (~> 0.1)
tzinfo (0.3.33)
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
+ validate_email (0.1.5)
+ activemodel (>= 3.0)
+ mail (>= 2.2.5)
+ validate_url (0.2.0)
+ activemodel (>= 3.0.0)
+ warden (1.1.1)
+ rack (>= 1.0)
PLATFORMS
ruby
DEPENDENCIES
+ activeadmin (= 0.4.3)
coffee-rails (~> 3.1.1)
+ factory_girl_rails (= 1.3.0)
+ formtastic (= 2.1.1)
jquery-rails
+ meta_search (>= 1.1.0.pre)
+ pg
rails (= 3.1.3)
+ rspec-rails (= 2.9.0)
sass-rails (~> 3.1.5)
+ shoulda (= 2.11.3)
sqlite3
turn (= 0.8.2)
+ twitter (= 2.2.2)
uglifier (>= 1.0.3)
+ validate_email (= 0.1.5)
+ validate_url (= 0.2.0)
View
44 app/admin/dashboards.rb
@@ -0,0 +1,44 @@
+ActiveAdmin::Dashboards.build do
+
+ # Define your dashboard sections here. Each block will be
+ # rendered on the dashboard in the context of the view. So just
+ # return the content which you would like to display.
+
+ # == Simple Dashboard Section
+ # Here is an example of a simple dashboard section
+ #
+ # section "Recent Posts" do
+ # ul do
+ # Post.recent(5).collect do |post|
+ # li link_to(post.title, admin_post_path(post))
+ # end
+ # end
+ # end
+
+ # == Render Partial Section
+ # The block is rendered within the context of the view, so you can
+ # easily render a partial rather than build content in ruby.
+ #
+ # section "Recent Posts" do
+ # div do
+ # render 'recent_posts' # => this will render /app/views/admin/dashboard/_recent_posts.html.erb
+ # end
+ # end
+
+ # == Section Ordering
+ # The dashboard sections are ordered by a given priority from top left to
+ # bottom right. The default priority is 10. By giving a section numerically lower
+ # priority it will be sorted higher. For example:
+ #
+ # section "Recent Posts", :priority => 10
+ # section "Recent User", :priority => 1
+ #
+ # Will render the "Recent Users" then the "Recent Posts" sections on the dashboard.
+
+ # == Conditionally Display
+ # Provide a method name or Proc object to conditionally render a section at run time.
+ #
+ # section "Membership Summary", :if => :memberships_enabled?
+ # section "Membership Summary", :if => Proc.new { current_admin_user.account.memberships.any? }
+
+end
View
76 app/admin/employees.rb
@@ -0,0 +1,76 @@
+ActiveAdmin.register Employee do
+ filter :name
+ filter :email
+ #begin
+ # filter :team_id , :as => :select, :collection => Team.order('name ASC')
+ #rescue
+ #end
+ index do
+ column 'Profile Picture' do |employee|
+ image_tag employee.twitter_profile_picture
+ end
+ column :name
+ column :email
+ column :mobile_number
+ column :landline_number
+ column 'Facebook URL' do |employee|
+ employee.facebook_url.blank? ? 'empty' : link_to(employee.facebook_url, employee.facebook_url)
+ end
+ column 'Twitter URL' do |employee|
+ employee.twitter_url.blank? ? 'empty' : link_to(employee.twitter_url, employee.twitter_url)
+ end
+ default_actions
+ end
+
+ form do |f|
+ f.inputs 'Details' do
+ f.input :name
+ f.input :email
+ f.input :mobile_number
+ f.input :landline_number
+ f.input :facebook_url
+ f.input :twitter_url
+ f.input :twitter_username
+ end
+ f.inputs "Teams" do
+ f.has_many :employee_teams do |employee_team|
+ employee_team.input :team_id, :as => :select, :collection => Team.order('name ASC')
+ end
+ end
+ f.buttons
+ end
+
+ show do |employee|
+ attributes_table_for employee do
+ row 'Profile Picture'do
+ image_tag employee.twitter_profile_picture
+ end
+ row :name
+ row :email
+ row :mobile_number
+ row :landline_number
+ row :facebook_url
+ row :twitter_url
+ row :twitter_username
+ row 'Teams: 'do
+ ul do
+ employee.teams.each do |team|
+ li do
+ link_to team.name, admin_team_path(team)
+ end
+ end
+ end
+ end
+ end
+ end
+ before_create do |employee|
+ unless employee.twitter_username.blank?
+ begin
+ profile_picture = Twitter.user(employee.twitter_username).profile_image_url
+ rescue
+ profile_picture = nil
+ end
+ end
+ employee.twitter_profile_picture = profile_picture
+ end
+end
View
32 app/admin/teams.rb
@@ -0,0 +1,32 @@
+ActiveAdmin.register Team do
+ filter :name
+ index do
+ column :name
+ column :description
+ default_actions
+ end
+
+ form do |f|
+ f.inputs 'Details' do
+ f.input :name
+ f.input :description
+ end
+ f.buttons
+ end
+
+ show do |team|
+ attributes_table_for team do
+ row :name
+ row :description
+ row 'Employees: 'do
+ ul do
+ team.employees.each do |employee|
+ li do
+ link_to employee.name, admin_employee_path(employee)
+ end
+ end
+ end
+ end
+ end
+ end
+end
View
1 app/assets/javascripts/active_admin.js
@@ -0,0 +1 @@
+//= require active_admin/base
View
6 app/assets/stylesheets/active_admin.css.scss
@@ -0,0 +1,6 @@
+// Active Admin CSS Styles
+@import "active_admin/mixins";
+@import "active_admin/base";
+
+// To customize the Active Admin interfaces, add your
+// styles here:
View
9 app/models/admin_user.rb
@@ -0,0 +1,9 @@
+class AdminUser < ActiveRecord::Base
+ # Include default devise modules. Others available are:
+ # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
+ devise :database_authenticatable,
+ :recoverable, :rememberable, :trackable, :validatable
+
+ # Setup accessible (or protected) attributes for your model
+ attr_accessible :email, :password, :password_confirmation, :remember_me
+end
View
14 app/models/employee.rb
@@ -0,0 +1,14 @@
+class Employee < ActiveRecord::Base
+
+ validates_presence_of :name, :mobile_number, :landline_number, :twitter_username, :email
+ validates :facebook_url, :url => { :allow_blank => true }
+ validates :twitter_url, :url => { :allow_blank => true }
+ validates :email, :email => { :allow_blank => false }
+ attr_accessible :name, :email, :mobile_number, :landline_number, :twitter_url, :facebook_url, :twitter_username, :employee_teams_attributes
+
+
+ has_many :employee_teams, :class_name => 'TeamEmployee', :foreign_key => 'employee_id', :dependent => :destroy
+ has_many :teams, :through => :employee_teams
+
+ accepts_nested_attributes_for :employee_teams
+end
View
9 app/models/team.rb
@@ -0,0 +1,9 @@
+class Team < ActiveRecord::Base
+ validates_presence_of :name
+ validates_uniqueness_of :name
+ attr_accessible :name, :description
+
+ has_many :team_employees, :dependent => :destroy
+ has_many :employees, :through => :team_employees
+ #accepts_nested_attributes_for :employees
+end
View
5 app/models/team_employee.rb
@@ -0,0 +1,5 @@
+class TeamEmployee < ActiveRecord::Base
+ validates_uniqueness_of :team_id, :scope => :employee_id
+ belongs_to :employee
+ belongs_to :team
+end
View
1 config/application.rb
@@ -41,7 +41,6 @@ class Application < Rails::Application
# Enable the asset pipeline
config.assets.enabled = true
-
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
View
6 config/database.yml
@@ -17,9 +17,3 @@ test:
database: db/test.sqlite3
pool: 5
timeout: 5000
-
-production:
- adapter: sqlite3
- database: db/production.sqlite3
- pool: 5
- timeout: 5000
View
2 config/environments/production.rb
@@ -44,7 +44,7 @@
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
-
+ config.assets.initialize_on_precompile = false
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
View
129 config/initializers/active_admin.rb
@@ -0,0 +1,129 @@
+ActiveAdmin.setup do |config|
+
+ # == Site Title
+ #
+ # Set the title that is displayed on the main layout
+ # for each of the active admin pages.
+ #
+ config.site_title = "Agent007"
+
+ # Set the link url for the title. For example, to take
+ # users to your main site. Defaults to no link.
+ #
+ # config.site_title_link = "/"
+
+ # Set an optional image to be displayed for the header
+ # instead of a string (overrides :site_title)
+ #
+ # Note: Recommended image height is 21px to properly fit in the header
+ #
+ # config.site_title_image = "/images/logo.png"
+
+ # == Default Namespace
+ #
+ # Set the default namespace each administration resource
+ # will be added to.
+ #
+ # eg:
+ # config.default_namespace = :hello_world
+ #
+ # This will create resources in the HelloWorld module and
+ # will namespace routes to /hello_world/*
+ #
+ # To set no namespace by default, use:
+ # config.default_namespace = false
+ #
+ # Default:
+ # config.default_namespace = :admin
+ #
+ # You can customize the settings for each namespace by using
+ # a namespace block. For example, to change the site title
+ # within a namespace:
+ #
+ # config.namespace :admin do |admin|
+ # admin.site_title = "Custom Admin Title"
+ # end
+ #
+ # This will ONLY change the title for the admin section. Other
+ # namespaces will continue to use the main "site_title" configuration.
+
+ # == User Authentication
+ #
+ # Active Admin will automatically call an authentication
+ # method in a before filter of all controller actions to
+ # ensure that there is a currently logged in admin user.
+ #
+ # This setting changes the method which Active Admin calls
+ # within the controller.
+ config.authentication_method = :authenticate_admin_user!
+
+
+ # == Current User
+ #
+ # Active Admin will associate actions with the current
+ # user performing them.
+ #
+ # This setting changes the method which Active Admin calls
+ # to return the currently logged in user.
+ config.current_user_method = :current_admin_user
+
+
+ # == Logging Out
+ #
+ # Active Admin displays a logout link on each screen. These
+ # settings configure the location and method used for the link.
+ #
+ # This setting changes the path where the link points to. If it's
+ # a string, the strings is used as the path. If it's a Symbol, we
+ # will call the method to return the path.
+ #
+ # Default:
+ config.logout_link_path = :destroy_admin_user_session_path
+
+ # This setting changes the http method used when rendering the
+ # link. For example :get, :delete, :put, etc..
+ #
+ # Default:
+ # config.logout_link_method = :get
+
+
+ # == Admin Comments
+ #
+ # Admin comments allow you to add comments to any model for admin use.
+ # Admin comments are enabled by default.
+ #
+ # Default:
+ # config.allow_comments = true
+ #
+ # You can turn them on and off for any given namespace by using a
+ # namespace config block.
+ #
+ # Eg:
+ # config.namespace :without_comments do |without_comments|
+ # without_comments.allow_comments = false
+ # end
+
+
+ # == Controller Filters
+ #
+ # You can add before, after and around filters to all of your
+ # Active Admin resources from here.
+ #
+ # config.before_filter :do_something_awesome
+
+
+ # == Register Stylesheets & Javascripts
+ #
+ # We recommend using the built in Active Admin layout and loading
+ # up your own stylesheets / javascripts to customize the look
+ # and feel.
+ #
+ # To load a stylesheet:
+ # config.register_stylesheet 'my_stylesheet.css'
+ #
+ # You can provide an options hash for more control, which is passed along to stylesheet_link_tag():
+ # config.register_stylesheet 'my_print_stylesheet.css', :media => :print
+ #
+ # To load a javascript file:
+ # config.register_javascript 'my_javascript.js'
+end
View
223 config/initializers/devise.rb
@@ -0,0 +1,223 @@
+# Use this hook to configure devise mailer, warden hooks and so forth.
+# Many of these configuration options can be set straight in your model.
+Devise.setup do |config|
+ # ==> Mailer Configuration
+ # Configure the e-mail address which will be shown in Devise::Mailer,
+ # note that it will be overwritten if you use your own mailer class with default "from" parameter.
+ config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
+
+ # Configure the class responsible to send e-mails.
+ # config.mailer = "Devise::Mailer"
+
+ # Automatically apply schema changes in tableless databases
+ config.apply_schema = false
+
+ # ==> ORM configuration
+ # Load and configure the ORM. Supports :active_record (default) and
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
+ # available as additional gems.
+ require 'devise/orm/active_record'
+
+ # ==> Configuration for any authentication mechanism
+ # Configure which keys are used when authenticating a user. The default is
+ # just :email. You can configure it to use [:username, :subdomain], so for
+ # authenticating a user, both parameters are required. Remember that those
+ # parameters are used only when authenticating and not when retrieving from
+ # session. If you need permissions, you should implement that in a before filter.
+ # You can also supply a hash where the value is a boolean determining whether
+ # or not authentication should be aborted when the value is not present.
+ # config.authentication_keys = [ :email ]
+
+ # Configure parameters from the request object used for authentication. Each entry
+ # given should be a request method and it will automatically be passed to the
+ # find_for_authentication method and considered in your model lookup. For instance,
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
+ # config.request_keys = []
+
+ # Configure which authentication keys should be case-insensitive.
+ # These keys will be downcased upon creating or modifying a user and when used
+ # to authenticate or find a user. Default is :email.
+ config.case_insensitive_keys = [ :email ]
+
+ # Configure which authentication keys should have whitespace stripped.
+ # These keys will have whitespace before and after removed upon creating or
+ # modifying a user and when used to authenticate or find a user. Default is :email.
+ config.strip_whitespace_keys = [ :email ]
+
+ # Tell if authentication through request.params is enabled. True by default.
+ # It can be set to an array that will enable params authentication only for the
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
+ # enable it only for database (email + password) authentication.
+ # config.params_authenticatable = true
+
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
+ # It can be set to an array that will enable http authentication only for the
+ # given strategies, for example, `config.http_authenticatable = [:token]` will
+ # enable it only for token authentication.
+ # config.http_authenticatable = false
+
+ # If http headers should be returned for AJAX requests. True by default.
+ # config.http_authenticatable_on_xhr = true
+
+ # The realm used in Http Basic Authentication. "Application" by default.
+ # config.http_authentication_realm = "Application"
+
+ # It will change confirmation, password recovery and other workflows
+ # to behave the same regardless if the e-mail provided was right or wrong.
+ # Does not affect registerable.
+ # config.paranoid = true
+
+ # By default Devise will store the user in session. You can skip storage for
+ # :http_auth and :token_auth by adding those symbols to the array below.
+ # Notice that if you are skipping storage for all authentication paths, you
+ # may want to disable generating routes to Devise's sessions controller by
+ # passing :skip => :sessions to `devise_for` in your config/routes.rb
+ config.skip_session_storage = [:http_auth]
+
+ # ==> Configuration for :database_authenticatable
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
+ # using other encryptors, it sets how many times you want the password re-encrypted.
+ #
+ # Limiting the stretches to just one in testing will increase the performance of
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
+ # a value less than 10 in other environments.
+ config.stretches = Rails.env.test? ? 1 : 10
+
+ # Setup a pepper to generate the encrypted password.
+ # config.pepper = "31c8e9a9d921c26e1b9b7ebbcfd7572cccbe655de1223c4937c3db0436edbb8fb6fbf199d590d9c78fe2af5007f6df9074e7c48c2e187511f2d0309ad4c98a45"
+
+ # ==> Configuration for :confirmable
+ # A period that the user is allowed to access the website even without
+ # confirming his account. For instance, if set to 2.days, the user will be
+ # able to access the website for two days without confirming his account,
+ # access will be blocked just in the third day. Default is 0.days, meaning
+ # the user cannot access the website without confirming his account.
+ # config.allow_unconfirmed_access_for = 2.days
+
+ # If true, requires any email changes to be confirmed (exctly the same way as
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
+ # db field (see migrations). Until confirmed new email is stored in
+ # unconfirmed email column, and copied to email column on successful confirmation.
+ config.reconfirmable = true
+
+ # Defines which key will be used when confirming an account
+ # config.confirmation_keys = [ :email ]
+
+ # ==> Configuration for :rememberable
+ # The time the user will be remembered without asking for credentials again.
+ # config.remember_for = 2.weeks
+
+ # If true, extends the user's remember period when remembered via cookie.
+ # config.extend_remember_period = false
+
+ # If true, uses the password salt as remember token. This should be turned
+ # to false if you are not using database authenticatable.
+ config.use_salt_as_remember_token = true
+
+ # Options to be passed to the created cookie. For instance, you can set
+ # :secure => true in order to force SSL only cookies.
+ # config.cookie_options = {}
+
+ # ==> Configuration for :validatable
+ # Range for password length. Default is 6..128.
+ # config.password_length = 6..128
+
+ # Email regex used to validate email formats. It simply asserts that
+ # an one (and only one) @ exists in the given string. This is mainly
+ # to give user feedback and not to assert the e-mail validity.
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
+
+ # ==> Configuration for :timeoutable
+ # The time you want to timeout the user session without activity. After this
+ # time the user will be asked for credentials again. Default is 30 minutes.
+ # config.timeout_in = 30.minutes
+
+ # ==> Configuration for :lockable
+ # Defines which strategy will be used to lock an account.
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
+ # :none = No lock strategy. You should handle locking by yourself.
+ # config.lock_strategy = :failed_attempts
+
+ # Defines which key will be used when locking and unlocking an account
+ # config.unlock_keys = [ :email ]
+
+ # Defines which strategy will be used to unlock an account.
+ # :email = Sends an unlock link to the user email
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
+ # :both = Enables both strategies
+ # :none = No unlock strategy. You should handle unlocking by yourself.
+ # config.unlock_strategy = :both
+
+ # Number of authentication tries before locking an account if lock_strategy
+ # is failed attempts.
+ # config.maximum_attempts = 20
+
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
+ # config.unlock_in = 1.hour
+
+ # ==> Configuration for :recoverable
+ #
+ # Defines which key will be used when recovering the password for an account
+ # config.reset_password_keys = [ :email ]
+
+ # Time interval you can reset your password with a reset password key.
+ # Don't put a too small interval or your users won't have the time to
+ # change their passwords.
+ config.reset_password_within = 6.hours
+
+ # ==> Configuration for :encryptable
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
+ # REST_AUTH_SITE_KEY to pepper)
+ # config.encryptor = :sha512
+
+ # ==> Configuration for :token_authenticatable
+ # Defines name of the authentication token params key
+ # config.token_authentication_key = :auth_token
+
+ # ==> Scopes configuration
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
+ # "users/sessions/new". It's turned off by default because it's slower if you
+ # are using only default views.
+ # config.scoped_views = false
+
+ # Configure the default scope given to Warden. By default it's the first
+ # devise role declared in your routes (usually :user).
+ # config.default_scope = :user
+
+ # Configure sign_out behavior.
+ # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
+ # The default is true, which means any logout action will sign out all active scopes.
+ # config.sign_out_all_scopes = true
+
+ # ==> Navigation configuration
+ # Lists the formats that should be treated as navigational. Formats like
+ # :html, should redirect to the sign in page when the user does not have
+ # access, but formats like :xml or :json, should return 401.
+ #
+ # If you have any extra navigational formats, like :iphone or :mobile, you
+ # should add them to the navigational formats lists.
+ #
+ # The "*/*" below is required to match Internet Explorer requests.
+ # config.navigational_formats = ["*/*", :html]
+
+ # The default HTTP method used to sign out a resource. Default is :delete.
+ config.sign_out_via = :delete
+
+ # ==> OmniAuth
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
+ # up on your models and hooks.
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
+
+ # ==> Warden configuration
+ # If you want to use other strategies, that are not supported by Devise, or
+ # change the failure app, you can configure them inside the config.warden block.
+ #
+ # config.warden do |manager|
+ # manager.intercept_401 = false
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
+ # end
+end
View
4 config/initializers/twitter.rb
@@ -0,0 +1,4 @@
+Twitter.configure do |config|
+ config.consumer_key = 'MLC24rwjz5o6q8VyO1WXg'
+ config.consumer_secret = 'knJqxmQ6WyEISihcLTbQcUJXIdDyvTjMz5U7kJnOLQ'
+end
View
57 config/locales/devise.en.yml
@@ -0,0 +1,57 @@
+# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
+
+en:
+ errors:
+ messages:
+ expired: "has expired, please request a new one"
+ not_found: "not found"
+ already_confirmed: "was already confirmed, please try signing in"
+ not_locked: "was not locked"
+ not_saved:
+ one: "1 error prohibited this %{resource} from being saved:"
+ other: "%{count} errors prohibited this %{resource} from being saved:"
+
+ devise:
+ failure:
+ already_authenticated: 'You are already signed in.'
+ unauthenticated: 'You need to sign in or sign up before continuing.'
+ unconfirmed: 'You have to confirm your account before continuing.'
+ locked: 'Your account is locked.'
+ invalid: 'Invalid email or password.'
+ invalid_token: 'Invalid authentication token.'
+ timeout: 'Your session expired, please sign in again to continue.'
+ inactive: 'Your account was not activated yet.'
+ sessions:
+ signed_in: 'Signed in successfully.'
+ signed_out: 'Signed out successfully.'
+ passwords:
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
+ updated: 'Your password was changed successfully. You are now signed in.'
+ updated_not_active: 'Your password was changed successfully.'
+ send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
+ confirmations:
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
+ send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
+ registrations:
+ signed_up: 'Welcome! You have signed up successfully.'
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
+ updated: 'You updated your account successfully.'
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
+ unlocks:
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
+ omniauth_callbacks:
+ success: 'Successfully authorized from %{kind} account.'
+ failure: 'Could not authorize you from %{kind} because "%{reason}".'
+ mailer:
+ confirmation_instructions:
+ subject: 'Confirmation instructions'
+ reset_password_instructions:
+ subject: 'Reset password instructions'
+ unlock_instructions:
+ subject: 'Unlock Instructions'
View
6 config/routes.rb
@@ -1,4 +1,8 @@
Agent007::Application.routes.draw do
+ ActiveAdmin.routes(self)
+
+ devise_for :admin_users, ActiveAdmin::Devise.config
+
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -48,7 +52,7 @@
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
- # root :to => 'welcome#index'
+ root :to => 'admin/dashboard#index'
# See how all your routes lay out with "rake routes"
View
17 db/migrate/20120426114215_create_admin_notes.rb
@@ -0,0 +1,17 @@
+class CreateAdminNotes < ActiveRecord::Migration
+ def self.up
+ create_table :admin_notes do |t|
+ t.string :resource_id, :null => false
+ t.string :resource_type, :null => false
+ t.references :admin_user, :polymorphic => true
+ t.text :body
+ t.timestamps
+ end
+ add_index :admin_notes, [:resource_type, :resource_id]
+ add_index :admin_notes, [:admin_user_type, :admin_user_id]
+ end
+
+ def self.down
+ drop_table :admin_notes
+ end
+end
View
25 db/migrate/20120426114216_move_admin_notes_to_comments.rb
@@ -0,0 +1,25 @@
+class MoveAdminNotesToComments < ActiveRecord::Migration
+ def self.up
+ remove_index :admin_notes, [:admin_user_type, :admin_user_id]
+ rename_table :admin_notes, :active_admin_comments
+ rename_column :active_admin_comments, :admin_user_type, :author_type
+ rename_column :active_admin_comments, :admin_user_id, :author_id
+ add_column :active_admin_comments, :namespace, :string
+ add_index :active_admin_comments, [:namespace]
+ add_index :active_admin_comments, [:author_type, :author_id]
+
+ # Update all the existing comments to the default namespace
+ say "Updating any existing comments to the #{ActiveAdmin.application.default_namespace} namespace."
+ execute "UPDATE active_admin_comments SET namespace='#{ActiveAdmin.application.default_namespace}'"
+ end
+
+ def self.down
+ remove_index :active_admin_comments, :column => [:author_type, :author_id]
+ remove_index :active_admin_comments, :column => [:namespace]
+ remove_column :active_admin_comments, :namespace
+ rename_column :active_admin_comments, :author_id, :admin_user_id
+ rename_column :active_admin_comments, :author_type, :admin_user_type
+ rename_table :active_admin_comments, :admin_notes
+ add_index :admin_notes, [:admin_user_type, :admin_user_id]
+ end
+end
View
50 db/migrate/20120426164157_devise_create_admin_users.rb
@@ -0,0 +1,50 @@
+class DeviseCreateAdminUsers < ActiveRecord::Migration
+ def change
+ create_table(:admin_users) do |t|
+ ## Database authenticatable
+ t.string :email, :null => false, :default => ""
+ t.string :encrypted_password, :null => false, :default => ""
+
+ ## Recoverable
+ t.string :reset_password_token
+ t.datetime :reset_password_sent_at
+
+ ## Rememberable
+ t.datetime :remember_created_at
+
+ ## Trackable
+ t.integer :sign_in_count, :default => 0
+ t.datetime :current_sign_in_at
+ t.datetime :last_sign_in_at
+ t.string :current_sign_in_ip
+ t.string :last_sign_in_ip
+
+ ## Encryptable
+ # t.string :password_salt
+
+ ## Confirmable
+ # t.string :confirmation_token
+ # t.datetime :confirmed_at
+ # t.datetime :confirmation_sent_at
+ # t.string :unconfirmed_email # Only if using reconfirmable
+
+ ## Lockable
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
+ # t.datetime :locked_at
+
+ ## Token authenticatable
+ # t.string :authentication_token
+ t.timestamps
+ end
+
+ # Create a default user
+ AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password')
+
+ add_index :admin_users, :email, :unique => true
+ add_index :admin_users, :reset_password_token, :unique => true
+ # add_index :admin_users, :confirmation_token, :unique => true
+ # add_index :admin_users, :unlock_token, :unique => true
+ # add_index :admin_users, :authentication_token, :unique => true
+ end
+end
View
15 db/migrate/20120426220345_create_employees.rb
@@ -0,0 +1,15 @@
+class CreateEmployees < ActiveRecord::Migration
+ def change
+ create_table :employees do |t|
+ t.string :name
+ t.string :email
+ t.string :mobile_number
+ t.string :landline_number
+ t.string :twitter_url
+ t.string :facebook_url
+ t.string :twitter_username
+
+ t.timestamps
+ end
+ end
+end
View
10 db/migrate/20120426220819_create_teams.rb
@@ -0,0 +1,10 @@
+class CreateTeams < ActiveRecord::Migration
+ def change
+ create_table :teams do |t|
+ t.text :description
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
View
10 db/migrate/20120426234935_create_team_employees.rb
@@ -0,0 +1,10 @@
+class CreateTeamEmployees < ActiveRecord::Migration
+ def change
+ create_table :team_employees do |t|
+ t.integer :team_id
+ t.integer :employee_id
+
+ t.timestamps
+ end
+ end
+end
View
5 db/migrate/20120427043229_add_twitter_profile_picture_to_employees.rb
@@ -0,0 +1,5 @@
+class AddTwitterProfilePictureToEmployees < ActiveRecord::Migration
+ def change
+ add_column :employees, :twitter_profile_picture, :string
+ end
+end
View
76 db/schema.rb
@@ -0,0 +1,76 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120427043229) do
+
+ create_table "active_admin_comments", :force => true do |t|
+ t.string "resource_id", :null => false
+ t.string "resource_type", :null => false
+ t.integer "author_id"
+ t.string "author_type"
+ t.text "body"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.string "namespace"
+ end
+
+ add_index "active_admin_comments", ["author_type", "author_id"], :name => "index_active_admin_comments_on_author_type_and_author_id"
+ add_index "active_admin_comments", ["namespace"], :name => "index_active_admin_comments_on_namespace"
+ add_index "active_admin_comments", ["resource_type", "resource_id"], :name => "index_admin_notes_on_resource_type_and_resource_id"
+
+ create_table "admin_users", :force => true do |t|
+ t.string "email", :default => "", :null => false
+ t.string "encrypted_password", :default => "", :null => false
+ t.string "reset_password_token"
+ t.datetime "reset_password_sent_at"
+ t.datetime "remember_created_at"
+ t.integer "sign_in_count", :default => 0
+ t.datetime "current_sign_in_at"
+ t.datetime "last_sign_in_at"
+ t.string "current_sign_in_ip"
+ t.string "last_sign_in_ip"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true
+ add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true
+
+ create_table "employees", :force => true do |t|
+ t.string "name"
+ t.string "email"
+ t.string "mobile_number"
+ t.string "landline_number"
+ t.string "twitter_url"
+ t.string "facebook_url"
+ t.string "twitter_username"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.string "twitter_profile_picture"
+ end
+
+ create_table "team_employees", :force => true do |t|
+ t.integer "team_id"
+ t.integer "employee_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "teams", :force => true do |t|
+ t.text "description"
+ t.string "name"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
View
241 public/index.html
@@ -1,241 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Ruby on Rails: Welcome aboard</title>
- <style type="text/css" media="screen">
- body {
- margin: 0;
- margin-bottom: 25px;
- padding: 0;
- background-color: #f0f0f0;
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
- font-size: 13px;
- color: #333;
- }
-
- h1 {
- font-size: 28px;
- color: #000;
- }
-
- a {color: #03c}
- a:hover {
- background-color: #03c;
- color: white;
- text-decoration: none;
- }
-
-
- #page {
- background-color: #f0f0f0;
- width: 750px;
- margin: 0;
- margin-left: auto;
- margin-right: auto;
- }
-
- #content {
- float: left;
- background-color: white;
- border: 3px solid #aaa;
- border-top: none;
- padding: 25px;
- width: 500px;
- }
-
- #sidebar {
- float: right;
- width: 175px;
- }
-
- #footer {
- clear: both;
- }
-
- #header, #about, #getting-started {
- padding-left: 75px;
- padding-right: 30px;
- }
-
-
- #header {
- background-image: url("/assets/rails.png");
- background-repeat: no-repeat;
- background-position: top left;
- height: 64px;
- }
- #header h1, #header h2 {margin: 0}
- #header h2 {
- color: #888;
- font-weight: normal;
- font-size: 16px;
- }
-
-
- #about h3 {
- margin: 0;
- margin-bottom: 10px;
- font-size: 14px;
- }
-
- #about-content {
- background-color: #ffd;
- border: 1px solid #fc0;
- margin-left: -55px;
- margin-right: -10px;
- }
- #about-content table {
- margin-top: 10px;
- margin-bottom: 10px;
- font-size: 11px;
- border-collapse: collapse;
- }
- #about-content td {
- padding: 10px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- #about-content td.name {color: #555}
- #about-content td.value {color: #000}
-
- #about-content ul {
- padding: 0;
- list-style-type: none;
- }
-
- #about-content.failure {
- background-color: #fcc;
- border: 1px solid #f00;
- }
- #about-content.failure p {
- margin: 0;
- padding: 10px;
- }
-
-
- #getting-started {
- border-top: 1px solid #ccc;
- margin-top: 25px;
- padding-top: 15px;
- }
- #getting-started h1 {
- margin: 0;
- font-size: 20px;
- }
- #getting-started h2 {
- margin: 0;
- font-size: 14px;
- font-weight: normal;
- color: #333;
- margin-bottom: 25px;
- }
- #getting-started ol {
- margin-left: 0;
- padding-left: 0;
- }
- #getting-started li {
- font-size: 18px;
- color: #888;
- margin-bottom: 25px;
- }
- #getting-started li h2 {
- margin: 0;
- font-weight: normal;
- font-size: 18px;
- color: #333;
- }
- #getting-started li p {
- color: #555;
- font-size: 13px;
- }
-
-
- #sidebar ul {
- margin-left: 0;
- padding-left: 0;
- }
- #sidebar ul h3 {
- margin-top: 25px;
- font-size: 16px;
- padding-bottom: 10px;
- border-bottom: 1px solid #ccc;
- }
- #sidebar li {
- list-style-type: none;
- }
- #sidebar ul.links li {
- margin-bottom: 5px;
- }
-
- .filename {
- font-style: italic;
- }
- </style>
- <script type="text/javascript">
- function about() {
- info = document.getElementById('about-content');
- if (window.XMLHttpRequest)
- { xhr = new XMLHttpRequest(); }
- else
- { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
- xhr.open("GET","rails/info/properties",false);
- xhr.send("");
- info.innerHTML = xhr.responseText;
- info.style.display = 'block'
- }
- </script>
- </head>
- <body>
- <div id="page">
- <div id="sidebar">
- <ul id="sidebar-items">
- <li>
- <h3>Browse the documentation</h3>
- <ul class="links">
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
- <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
- <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
- <div id="content">
- <div id="header">
- <h1>Welcome aboard</h1>
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
- </div>
-
- <div id="about">
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
- <div id="about-content" style="display: none"></div>
- </div>
-
- <div id="getting-started">
- <h1>Getting started</h1>
- <h2>Here&rsquo;s how to get rolling:</h2>
-
- <ol>
- <li>
- <h2>Use <code>rails generate</code> to create your models and controllers</h2>
- <p>To see all available options, run it without parameters.</p>
- </li>
-
- <li>
- <h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
- <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
- </li>
-
- <li>
- <h2>Create your database</h2>
- <p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
- </li>
- </ol>
- </div>
- </div>
-
- <div id="footer">&nbsp;</div>
- </div>
- </body>
-</html>
View
87 spec/controllers/admin/employees_controller_spec.rb
@@ -0,0 +1,87 @@
+require 'spec_helper'
+
+describe Admin::EmployeesController do
+ it {{:post => "/admin/employees"}.should route_to(:controller => "admin/employees", :action => "create")}
+ it {{:get => "/admin/employees"}.should route_to(:controller => "admin/employees", :action => "index")}
+ it {{:get => "/admin/employees/new"}.should route_to(:controller => "admin/employees", :action => "new")}
+ it {{:get => "/admin/employees/1/edit"}.should route_to(:controller => "admin/employees", :action => "edit", :id => "1")}
+ it {{:get => "/admin/employees/1"}.should route_to(:controller => "admin/employees", :action => "show", :id => "1")}
+ it {{:put => "/admin/employees/1"}.should route_to(:controller => "admin/employees", :action => "update", :id => "1")}
+ it {{:delete => "/admin/employees/1"}.should route_to(:controller => "admin/employees", :action => "destroy", :id => "1")}
+
+ before do
+ @admin_user = Factory(:admin_user)
+ sign_in(@admin_user)
+ end
+
+ describe "#GET to index" do
+ it "should assign an array with employees" do
+ 3. times do
+ Factory(:employee)
+ end
+ get :index
+ response.should be_success
+ assigns(:employees).size.should eq 3
+ end
+ it "should assign an empty array if there are not employees" do
+ Employee.destroy_all
+ get :index
+ response.should be_success
+ assigns(:employees).size.should eq 0
+ end
+ end
+ describe "#POST to create" do
+ it "should create an employee when the required params was sent" do
+ team_id = Factory(:team).id
+ lambda do
+ post :create, :employee => Factory.attributes_for(:employee).merge({:employee_teams_attributes => [{:team_id => team_id}] })
+ end.should change(Employee,:count).by(1)
+ assigns(:employee).teams.size.should eq 1
+ end
+ it "should not create an employee if the required params was not sent" do
+ lambda do
+ post :create, :employee => {:name => "jdavix", :landline_number => "3434-343434-3434"}
+ end.should change(Employee,:count).by(0)
+ assigns(:employee).should_not be_valid
+ end
+ end
+ describe "#GET to new" do
+ it "should initialize an employee" do
+ get :new
+ assigns(:employee).class.name.should eq "Employee"
+ assigns(:employee).persisted?.should eq false
+ end
+ end
+
+ describe "#GET to edit" do
+ it "should assign the record found with the id given" do
+ employee_id = Factory(:employee).id
+ get :edit, :id => employee_id
+ assigns(:employee).id.should eq employee_id
+ end
+ end
+
+ describe "#PUT to update" do
+ before do
+ @employee = Factory(:employee)
+ @employee_id = @employee.id
+ end
+ it "should update the persisted object with the attributes sent" do
+ put :update, :employee => {:name => "jdavix24"}, :id => @employee_id
+ assigns(:employee).name.should eq "jdavix24"
+ end
+ it "should not update the employee if the param sent is not valid" do
+ put :update, :employee => {:email => "dfdfd"}, :id => @employee_id
+ assigns(:employee).should_not be_valid
+ end
+ end
+
+ describe "#DELETE to destroy" do
+ it "should destroy the employee identified by the id given" do
+ employee_id = Factory(:employee).id
+ lambda do
+ delete :destroy, :id => employee_id
+ end.should change(Employee, :count).by(-1)
+ end
+ end
+end
View
10 spec/factories/admin_users.rb
@@ -0,0 +1,10 @@
+FactoryGirl.define do
+ Factory.sequence :email do |i|
+ "email_#{i}@example.com"
+ end
+ factory :admin_user do |f|
+ f.sequence (:email){Factory.next(:email)}
+ password "password"
+ password_confirmation "password"
+ end
+end
View
12 spec/factories/employees.rb
@@ -0,0 +1,12 @@
+FactoryGirl.define do
+ Factory.sequence :name do |i|
+ "This is a name #{i}"
+ end
+ factory :employee do |f|
+ f.sequence (:name){Factory.next(:name)}
+ f.sequence (:email){Factory.next(:email)}
+ mobile_number '123-2323-2323'
+ landline_number '434-3434-3439'
+ twitter_username 'mytwitter'
+ end
+end
View
6 spec/factories/teams.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :team do |f|
+ f.sequence (:name){Factory.next(:name)}
+ description 'this is a description lorem impsum'
+ end
+end
View
16 spec/models/employee_spec.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe Employee do
+ describe "Model validators" do
+ before do
+ Factory(:employee)
+ end
+ it{should validate_presence_of :name}
+ it{should validate_presence_of :mobile_number}
+ it{should validate_presence_of :landline_number}
+ it{should validate_presence_of :twitter_username}
+ it{should validate_presence_of :email}
+ it{should have_many :employee_teams}
+ it{should have_many :teams}
+ end
+end
View
34 spec/spec_helper.rb
@@ -0,0 +1,34 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'rspec/autorun'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+RSpec.configure do |config|
+ config.include Devise::TestHelpers, :type => :controller
+end
+RSpec.configure do |config|
+ # ## Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ config.mock_with :rspec
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+end
View
0 test/fixtures/.gitkeep
No changes.
View
0 test/functional/.gitkeep
No changes.
View
0 test/integration/.gitkeep
No changes.
View
12 test/performance/browsing_test.rb
@@ -1,12 +0,0 @@
-require 'test_helper'
-require 'rails/performance_test_help'
-
-class BrowsingTest < ActionDispatch::PerformanceTest
- # Refer to the documentation for all available options
- # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
- # :output => 'tmp/performance', :formats => [:flat] }
-
- def test_homepage
- get '/'
- end
-end
View
13 test/test_helper.rb
@@ -1,13 +0,0 @@
-ENV["RAILS_ENV"] = "test"
-require File.expand_path('../../config/environment', __FILE__)
-require 'rails/test_help'
-
-class ActiveSupport::TestCase
- # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
- #
- # Note: You'll currently still have to declare fixtures explicitly in integration tests
- # -- they do not yet inherit this setting
- fixtures :all
-
- # Add more helper methods to be used by all tests here...
-end
View
0 test/unit/.gitkeep
No changes.

No commit comments for this range

Something went wrong with that request. Please try again.