Skip to content

Commit

Permalink
[checkpoint] new navbar / pepare jasimine and capybara
Browse files Browse the repository at this point in the history
* navbar v2 - now works when user reloads the page (from directive to service)
* prepare jasimne / capybara enviroment

@dodo121
  • Loading branch information
dodo121 committed Nov 30, 2015
1 parent 631fdc5 commit 76aeba0
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ group :development, :test do
gem 'rspec-rails'
gem 'rubocop'
gem 'jasmine'
gem 'capybara'
end

group :production do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Organizer = angular.module('Organizer')
Organizer.controller('IndexCtrl', ['$scope', ($scope) ->
Organizer.controller('IndexCtrl', ['$scope', 'Navbar', ($scope, Navbar) ->
Navbar.switchTo '#home'

$scope.title = 'Hello'
])

16 changes: 14 additions & 2 deletions app/assets/javascripts/controllers/notes/notesIndexCtrl.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Organizer = angular.module('Organizer')

Organizer.controller('NotesCtrl', ['$scope', '$location', '$resource', 'Note', ($scope, $location, $resource, Note) ->
Organizer.controller('NotesCtrl', ['$scope', '$location', '$resource', 'Note', 'Navbar', ($scope, $location, $resource, Note, Navbar) ->
Navbar.switchTo('#notes-link')

$scope.notes =
note: { content: 'Please wait'}

Expand All @@ -24,8 +26,18 @@ Organizer.directive('myNote', ['Note', (Note) ->
element.find('.edit-note').show().focus()

element.find('.edit-note').focusout ->
Note.updateNote(scope.note)
Note.saveNote(scope.note)

return true
}
])

Organizer.directive('addNote', [ ->
return {
restrict: 'A',
link: (scope, element, attrs) ->
element.on 'click', ->
log 'clicked new'
return true
}
])
Expand Down
16 changes: 0 additions & 16 deletions app/assets/javascripts/main.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,4 @@ Organizer.config(['$routeProvider', ($routeProvider) ->
$routeProvider.when('/notes', { templateUrl: 'notesIndex.html', controller: 'NotesCtrl' } )

$routeProvider.otherwise({ templateUrl: 'homeIndex.html', controller: 'IndexCtrl' } )
])

Organizer.directive('navLink', [ ->
return {
restrict: 'AEC',
link: (scope, element, attrs) ->
element.on 'click', ->
$('.nav-link').each ->
$(this).removeClass('active')

if element.hasClass('navbar-brand')
$('.nav-link.home').addClass('active')
else
element.addClass('active')
return true
}
])
21 changes: 21 additions & 0 deletions app/assets/javascripts/services/navbarService.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Organizer = angular.module('Organizer')

Organizer.factory('Navbar', ->
factory = {}

factory.switchTo = (cssClass) ->
factory.cleanup = ->
$('.nav-link').each ->
$(this).removeClass('active')

el = $('.navbar-nav').find(cssClass)

factory.cleanup()

if el.hasClass('navbar-brand')
$('.nav-link.home').addClass('active')
else
el.addClass('active')

return factory
)
5 changes: 3 additions & 2 deletions app/assets/javascripts/services/noteService.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Organizer.factory('Note', ['$resource', ($resource) ->
factory.destroy = (note) ->
note.$delete()

factory.updateNote = (note) ->
note.$save()
factory.saveNote = (note) ->
console.log note
if note.id == undefined then note.$create() else note.$save()

return factory
])
3 changes: 1 addition & 2 deletions app/assets/javascripts/templates/notesIndex.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%h1
Notes
.glyphicon.glyphicon-plus{'ng-click'=>'showForm'}
//%add-new.glyphicon.glyphicon-plus
.row
%my-note.col-sm-3{'ng-repeat'=>'note in notes'}
Expand All @@ -11,4 +11,3 @@
%input{'type' => 'text',
'class' => 'edit-note',
'ng-model'=> 'note.content' }

6 changes: 6 additions & 0 deletions app/assets/javascripts/templates/notesNew.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%my-note.col-sm-3
.well.well-sm
.glyphicon.glyphicon-remove.pull-right.delete_button{'ng-click'=>'ng-hide()'}
%input{'type' => 'text',
'class' => 'edit-note',
'ng-model'=> 'note.content' }
4 changes: 2 additions & 2 deletions app/views/layouts/_navbar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#bs-example-navbar-collapse-1.collapse.navbar-collapse
%ul.nav.navbar-nav
%li.active.nav-link.home
%li.active.nav-link#home
%a{:href => "#"}
Home
%span.sr-only (current)
%li.nav-link
%li.nav-link#notes-link
%a{:href => "#notes"} Notes
8 changes: 8 additions & 0 deletions spec/features/navbar_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

require 'rails_helper'

feature 'Navbar' do
scenario 'User visits the app' do
visit('/')
end
end
Empty file added spec/features/notes_spec.rb
Empty file.
12 changes: 12 additions & 0 deletions spec/javascripts/services/noteServiceSpec.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe 'NotesCtrl', ->
describe 'getAll', ->

describe 'destroy', ->
it 'removes note', ->

describe 'saveNote', ->
describe 'when note is new', ->
it 'creates new Note', ->

describe 'when note is not new', ->
it 'updates existing note', ->
2 changes: 1 addition & 1 deletion spec/javascripts/support/jasmine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ helpers:
# - **/*[sS]pec.js
#
spec_files:
- '**/*[sS]pec.js'
- '**/*[sS]pec.js.coffee'

# src_dir
#
Expand Down
53 changes: 53 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'capybara/rspec'
# Add additional requires below this line. Rails is not loaded until this point!

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|
# 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

# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
end
92 changes: 92 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end

# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
config.disable_monkey_patching!
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
=end
end

0 comments on commit 76aeba0

Please sign in to comment.