From aedfab27b9a03f41638fefb1b39857ca66a99257 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 2 Apr 2013 10:35:21 +0200 Subject: initial token model and unit test --- users/app/models/token.rb | 10 ++++++++++ users/test/unit/token_test.rb | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 users/app/models/token.rb create mode 100644 users/test/unit/token_test.rb diff --git a/users/app/models/token.rb b/users/app/models/token.rb new file mode 100644 index 0000000..9de6850 --- /dev/null +++ b/users/app/models/token.rb @@ -0,0 +1,10 @@ +class Token < CouchRest::Model::Base + + use_database :tokens + + property :user_id, String, accessible: false + + validates :user_id, presence: true + +end + diff --git a/users/test/unit/token_test.rb b/users/test/unit/token_test.rb new file mode 100644 index 0000000..d409265 --- /dev/null +++ b/users/test/unit/token_test.rb @@ -0,0 +1,24 @@ +require 'test_helper' + +class ClientCertificateTest < ActiveSupport::TestCase + + setup do + @user = FactoryGirl.create(:user) + end + + teardown do + @user.destroy + end + + test "new token for user" do + sample = Token.new(:user_id => @user.id) + assert sample.valid? + assert_equal @user.id, sample.user_id + end + + test "token checks for user" do + sample = Token.new + assert !sample.valid?, "Token should require a user record" + end + +end -- cgit v1.2.3