diff --git a/Gemfile b/Gemfile index b98c0d8ff..9a552a3b7 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,7 @@ gem 'carrierwave' gem 'uuidtools', '2.1.2' gem 'bcrypt-ruby', '3.0.1' gem 'jquery-rails' +gem 'rails3-jquery-autocomplete' gem 'activeadmin' gem "meta_search", '>= 1.1.0.pre' gem 'fog', "~> 1.3.1" diff --git a/Gemfile.lock b/Gemfile.lock index 7e6b7a190..26038cfc7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,9 +93,9 @@ GEM carrierwave (0.8.0) activemodel (>= 3.2.0) activesupport (>= 3.2.0) - childprocess (0.3.8) + childprocess (0.3.9) ffi (~> 1.0, >= 1.0.11) - clamp (0.5.0) + clamp (0.5.1) coderay (1.0.9) coffee-rails (3.2.2) coffee-script (>= 2.2.0) @@ -103,7 +103,7 @@ GEM coffee-script (2.2.0) coffee-script-source execjs - coffee-script-source (1.5.0) + coffee-script-source (1.4.0) country-select (1.1.1) daemons (1.1.9) database_cleaner (0.7.0) @@ -197,7 +197,7 @@ GEM multi_json (1.6.1) net-scp (1.0.6) net-ssh (>= 2.6.5) - net-ssh (2.6.5) + net-ssh (2.6.6) nokogiri (1.5.6) orm_adapter (0.4.0) pg (0.14.0) @@ -227,6 +227,8 @@ GEM activesupport (= 3.2.9) bundler (~> 1.0) railties (= 3.2.9) + rails3-jquery-autocomplete (1.0.11) + rails (~> 3.0) railties (3.2.9) actionpack (= 3.2.9) activesupport (= 3.2.9) @@ -259,12 +261,12 @@ GEM ruby-hmac (0.4.0) ruby-protocol-buffers (1.2.2) rubyzip (0.9.9) - sass (3.2.6) + sass (3.2.7) sass-rails (3.2.6) railties (~> 3.2.0) sass (>= 3.1.10) tilt (~> 1.3) - selenium-webdriver (2.30.0) + selenium-webdriver (2.31.0) childprocess (>= 0.2.5) multi_json (~> 1.0) rubyzip @@ -287,11 +289,11 @@ GEM eventmachine (>= 0.12.6) rack (>= 1.0.0) thor (0.15.4) - tilt (1.3.4) + tilt (1.3.5) treetop (1.4.12) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.35) + tzinfo (0.3.36) uglifier (1.3.0) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) @@ -320,6 +322,7 @@ DEPENDENCIES capybara carrierwave coffee-rails (~> 3.2.1) + coffee-script-source (~> 1.4.0) country-select database_cleaner (= 0.7.0) eventmachine (= 1.0.0) @@ -340,6 +343,7 @@ DEPENDENCIES pg_migrate pry rails (= 3.2.9) + rails3-jquery-autocomplete rspec-rails ruby-protocol-buffers (= 1.2.2) sass-rails (~> 3.2.3) diff --git a/app/admin/admin_user.rb b/app/admin/admin_user.rb deleted file mode 100644 index 3aac52f3e..000000000 --- a/app/admin/admin_user.rb +++ /dev/null @@ -1,20 +0,0 @@ -ActiveAdmin.register AdminUser do - index do - column :email - column :current_sign_in_at - column :last_sign_in_at - column :sign_in_count - default_actions - end - - filter :email - - form do |f| - f.inputs "Admin Details" do - f.input :email - f.input :password - f.input :password_confirmation - end - f.actions - end -end diff --git a/app/admin/jam_ruby_invited_users.rb b/app/admin/jam_ruby_invited_users.rb new file mode 100644 index 000000000..e1cc4f2b1 --- /dev/null +++ b/app/admin/jam_ruby_invited_users.rb @@ -0,0 +1,25 @@ +ActiveAdmin.register JamRuby::InvitedUser do + menu :label => 'Invite Users' + + config.sort_order = 'created_at' + + form :html => { :multipart => true } do |f| + f.inputs "Required Data" do + f.input :email, :as => :email, :hint => "The email of the person you want to invite" + f.input :sender,:as => :select, :as => :select, :collection => User.where('admin = true'), :value => nil, :hint => "If you are sending a personalized invitation, then select a user" + f.input :autofriend, :hint => "Do you want the sender of this invite to be friends upon invitation acceptance?" + + end + f.inputs "Optional Stuff" do + f.input :note, :input_html => { :class => 'autogrow' }, :hint => "You can add a personalized note, if you wish" + end + + f.buttons + + end + + #collection_action :upload_artifact, :method => :post do + # # Do some CSV importing work here... + # redirect_to :action => :index, :notice => "CSV imported successfully!" + #end +end diff --git a/app/admin/user.rb b/app/admin/user.rb new file mode 100644 index 000000000..f67079634 --- /dev/null +++ b/app/admin/user.rb @@ -0,0 +1,8 @@ + ActiveAdmin.register JamRuby::User do + # define routes for "autocomplete :admin_user, :email" + collection_action :autocomplete_user_email, :method => :get + + controller do + autocomplete :invited_user, :email + end +end diff --git a/app/assets/javascripts/active_admin.js b/app/assets/javascripts/active_admin.js index d2b66c59f..7498ec940 100644 --- a/app/assets/javascripts/active_admin.js +++ b/app/assets/javascripts/active_admin.js @@ -1 +1,2 @@ //= require active_admin/base +//= require autocomplete-rails \ No newline at end of file diff --git a/app/models/admin_user.rb b/app/models/admin_user.rb deleted file mode 100644 index 9654e04fd..000000000 --- a/app/models/admin_user.rb +++ /dev/null @@ -1,40 +0,0 @@ -class AdminUser < ActiveRecord::Base - # Include default devise modules. Others available are: - # :token_authenticatable, :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 - - def jam_user - JamRuby::User.where(:email => self.email)[0] - end - - def self.sync_users - JamRuby::User.where(:admin => true).each do |uu| - if (au = self.find_by_email(uu.email)).nil? - au = self.create(:email => uu.email) - au.update_attribute(:encrypted_password, uu.password_digest) - else - if au.encrypted_password != uu.password_digest - au.update_attribute(:encrypted_password, uu.password_digest) - end - end - end - - self.all.each do |au| - if uu = au.jam_user - if uu.admin? - if au.encrypted_password != uu.password_digest - au.update_attribute(:encrypted_password, uu.password_digest) - end - else - au.destroy - end - end - end - end - -end diff --git a/config/application.rb b/config/application.rb index a42f511a9..70117e4d4 100644 --- a/config/application.rb +++ b/config/application.rb @@ -2,14 +2,21 @@ require File.expand_path('../boot', __FILE__) require 'rails/all' +# initialize ActiveRecord's db connection +# why? Because user.rb uses validates :acceptance, which needs a connection to the database. if there is better way... +ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))[Rails.env]) + if defined?(Bundler) # If you precompile assets before deploying to production, use this line + Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end include JamRuby + + module JamAdmin class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. @@ -24,7 +31,7 @@ module JamAdmin # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Activate observers that should always be running. - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer + config.active_record.observers = "JamRuby::InvitedUserObserver" # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. diff --git a/config/initializers/active_admin.rb b/config/initializers/active_admin.rb index 2ac34eb21..6eaf50bd0 100644 --- a/config/initializers/active_admin.rb +++ b/config/initializers/active_admin.rb @@ -55,7 +55,7 @@ ActiveAdmin.setup do |config| # # This setting changes the method which Active Admin calls # within the controller. - config.authentication_method = :authenticate_admin_user! + config.authentication_method = :authenticate_user! # == Current User @@ -65,7 +65,7 @@ ActiveAdmin.setup do |config| # # This setting changes the method which Active Admin calls # to return the currently logged in user. - config.current_user_method = :current_admin_user + config.current_user_method = :current_user # == Logging Out @@ -78,7 +78,7 @@ ActiveAdmin.setup do |config| # will call the method to return the path. # # Default: - config.logout_link_path = :destroy_admin_user_session_path + config.logout_link_path = :destroy_user_session_path # This setting changes the http method used when rendering the # link. For example :get, :delete, :put, etc.. diff --git a/config/initializers/jam_ruby_user.rb b/config/initializers/jam_ruby_user.rb index 9c8ef68a5..dfaebced6 100644 --- a/config/initializers/jam_ruby_user.rb +++ b/config/initializers/jam_ruby_user.rb @@ -1,4 +1,4 @@ -class JamRuby::User + class JamRuby::User EMAIL_TMPL_WELCOME = 'welcome_message' EMAIL_TMPL_WELCOME_BETA = 'welcome_betauser' @@ -50,7 +50,7 @@ class JamRuby::User end def admin_user - AdminUser.where(:email => self.email)[0] + User.where(:email => self.email)[0] end after_create do @@ -62,7 +62,7 @@ class JamRuby::User if EMAIL_TMPL_WELCOMES.index(self.email_template).nil? self.email_template = EMAIL_TMPL_WELCOME end - UserMailer.send(self.email_template, self, "#{url}/#{self.signup_token}").deliver + # UserMailer.send(self.email_template, self, "#{url}/#{self.signup_token}").deliver end after_save do @@ -70,7 +70,7 @@ class JamRuby::User if self.admin_changed? if self.admin if self.admin_user.nil? - au = AdminUser.create(:email => self.email) + au = User.create(:email => self.email) au.update_attribute(:encrypted_password, self.password_digest) end else diff --git a/config/routes.rb b/config/routes.rb index 4942b7681..e03b212b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,8 @@ JamAdmin::Application.routes.draw do ActiveAdmin.routes(self) - devise_for :admin_users, ActiveAdmin::Devise.config + # ActiveAdmin::Devise.config, + devise_for :users, :class_name => "JamRuby::User" # The priority is based upon order of creation: # first created -> highest priority. diff --git a/spec/factories.rb b/spec/factories.rb index da3371e8a..438107c40 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,10 +1,33 @@ FactoryGirl.define do - factory :user, :class => AdminUser do + factory :user, :class => JamRuby::User do sequence(:email) { |n| "person_#{n}@example.com"} + sequence(:first_name) { |n| "Person" } + sequence(:last_name) { |n| "#{n}" } password "foobar" password_confirmation "foobar" - end + email_confirmed true + musician true + city "Apex" + state "NC" + country "USA" + terms_of_service true + + factory :admin do + admin true + end + + before(:create) do |user| + user.musician_instruments << FactoryGirl.build(:musician_instrument, user: user) + end + + factory :single_user_session do + after(:create) do |user, evaluator| + music_session = FactoryGirl.create(:music_session, :creator => user) + connection = FactoryGirl.create(:connection, :user => user, :music_session => music_session) + end + end + end factory :artifact_update, :class => JamRuby::ArtifactUpdate do sequence(:version) { |n| "0.1.#{n}" } uri { "http://somewhere/jkclient.msi" } @@ -13,4 +36,14 @@ FactoryGirl.define do sha1 { "blurp" } end + factory :musician_instrument, :class=> JamRuby::MusicianInstrument do + instrument { Instrument.find('electric guitar') } + proficiency_level 1 + priority 0 + end + + factory :instrument, :class => JamRuby::Instrument do + description { |n| "Instrument #{n}" } + end + end diff --git a/spec/features/artifact_updates_spec.rb b/spec/features/artifact_updates_spec.rb index c6e7df0b8..5c3279fec 100644 --- a/spec/features/artifact_updates_spec.rb +++ b/spec/features/artifact_updates_spec.rb @@ -7,7 +7,7 @@ describe "Artifact Update" do subject { page } - let(:user) { FactoryGirl.create(:user) } + let(:user) { FactoryGirl.create(:admin) } before { sign_in user } describe "crud" do diff --git a/spec/features/invited_users_spec.rb b/spec/features/invited_users_spec.rb new file mode 100644 index 000000000..0ddf9f89c --- /dev/null +++ b/spec/features/invited_users_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe InvitedUser do + + subject { page } + + # create an administrative user + let(:user) { FactoryGirl.create(:admin) } + + before { sign_in user } + + describe "enduser management" do + + # let's go the management page for users + before { visit admin_jam_ruby_invited_users_path } + it { should have_selector('h2', text: "Jam Ruby Invited Users") } + + describe "create service invite" do + + before do + + # create a new user + visit new_admin_jam_ruby_invited_user_path + fill_in "jam_ruby_invited_user_email", with: "some_silly_guy@jamkazam.com" + #fill_in "jam_ruby_invited_user_sender_id", with: "some_silly_guy@jamkazam.com" + #fill_in "jam_ruby_invited_user_autofriend", with: "some_silly_guy@jamkazam.com" + click_button "Create Invited user" + + end + + it { + should have_selector('.flash.flash_notice', text: "Invited user was successfully created." ); + UserMailer.deliveries.length.should == 1 + } + end + end +end diff --git a/spec/features/jam_ruby_users.rb b/spec/features/jam_ruby_users.rb deleted file mode 100644 index e1edda0ef..000000000 --- a/spec/features/jam_ruby_users.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'spec_helper' - -describe "End Users" do - - subject { page } - - # create an administrative user - let(:user) { FactoryGirl.create(:user) } - - before { sign_in user } - - describe "enduser management" do - - # let's go the management page for users - before { visit admin_jam_ruby_users_path } - it { should have_selector('h2', text: "Jam Ruby Users") } - - describe "create new user" do - - before do - - # create a new user - visit new_admin_jam_ruby_user_path - fill_in "jam_ruby_user_email", with: "some_silly_guy@sillyguys.com" - click_button "Create User" - - end - - it { - # ok we should see the a flash that the user was created, and that an email was sent - sleep 5 - save_and_open_page - should have_selector('.flash.flash_notice', text: "User was successfully created." ); - UserMailer.deliveries.length.should == 1 - } - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0d352bac4..7d3a7f216 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,11 +2,14 @@ # provision database require 'active_record' require 'jam_db' -require 'jam_ruby' require 'spec_db' # recreate test database and migrate it db_config = YAML::load(File.open('config/database.yml'))["test"] SpecDb::recreate_database(db_config) +ActiveRecord::Base.establish_connection(YAML::load(File.open('config/database.yml'))["test"]) + +require 'jam_ruby' + # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' diff --git a/spec/support/utilities.rb b/spec/support/utilities.rb index 94e08ed21..2055c9495 100644 --- a/spec/support/utilities.rb +++ b/spec/support/utilities.rb @@ -5,10 +5,10 @@ def cookie_jar end def sign_in(user) - visit new_admin_user_session_path # login page + visit new_user_session_path # login page fill_in "Email", with: user.email fill_in "Password", with: user.password - click_button "Login" + click_button "Sign in" # Sign in when not using Capybara as well. #cookie_jar[:remember_token] = user.remember_token