From 92d62b9f5c19a2a1cc0070b0074521882cce718b Mon Sep 17 00:00:00 2001 From: sdalal11 Date: Tue, 25 Mar 2025 07:27:28 +0000 Subject: [PATCH 1/3] changes in tests --- Dockerfile | 27 +-- Gemfile | 9 +- Gemfile.lock | 347 ------------------------------------ config/application.rb | 2 + config/database.yml.example | 4 +- config/environment.rb | 3 + test/models/role_test.rb | 29 +++ test/test_helper.rb | 2 + 8 files changed, 62 insertions(+), 361 deletions(-) delete mode 100644 Gemfile.lock diff --git a/Dockerfile b/Dockerfile index e89a49ee8..0b7eb4a3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,31 @@ -FROM ruby:3.2.7 +FROM ruby:3.3.4 LABEL maintainer="Ankur Mundra " -# Install dependencies + +# Install necessary system dependencies RUN apt-get update && \ - apt-get install -y curl && \ + apt-get install -y \ + curl \ + build-essential \ + libxml2-dev \ + libxslt1-dev \ + nodejs \ + netcat-openbsd && \ curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \ - apt-get install -y nodejs && \ - apt-get install -y netcat-openbsd + apt-get install -y nodejs # Set the working directory WORKDIR /app -# Copy your application files from current location to WORKDIR +# Copy your application files from the current location to WORKDIR COPY . . -# Install Ruby dependencies +# Install Ruby dependencies (with updated bundler version) RUN gem update --system && gem install bundler:2.4.7 -RUN bundle install +RUN bundle install --jobs 4 --retry 3 -EXPOSE 3002 +# Expose the necessary port for Rails server +EXPOSE 3002 -# Set the entry point +# Set the entry point (run your setup.sh script if needed) ENTRYPOINT ["/app/setup.sh"] diff --git a/Gemfile b/Gemfile index b5f47ee4b..99032d4ce 100644 --- a/Gemfile +++ b/Gemfile @@ -1,13 +1,17 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '3.2.7' +ruby '3.3.4' gem 'mysql2', '~> 0.5.5' gem 'puma', '~> 5.0' -gem 'rails', '~> 8.0', '>= 8.0.1' +gem 'rails', '~> 8.0.2' gem 'rswag-api' gem 'rswag-ui' +gem 'nokogiri', '>=1.12.0' # Updated to a more compatible version +gem 'rails-dom-testing', '2.2.0' # Added this gem explicitly + + # Build JSON APIs with ease [https://github.com/rails/jbuilder] # gem "jbuilder" @@ -36,6 +40,7 @@ gem 'lingua' # This is a really small gem that can be used to retrieve objects from the database in the order of the list given gem 'find_with_order' + group :development, :test do gem 'debug', platforms: %i[mri mingw x64_mingw] gem 'factory_bot_rails' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 9cca8ef5d..000000000 --- a/Gemfile.lock +++ /dev/null @@ -1,347 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - actioncable (8.0.1) - actionpack (= 8.0.1) - activesupport (= 8.0.1) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - zeitwerk (~> 2.6) - actionmailbox (8.0.1) - actionpack (= 8.0.1) - activejob (= 8.0.1) - activerecord (= 8.0.1) - activestorage (= 8.0.1) - activesupport (= 8.0.1) - mail (>= 2.8.0) - actionmailer (8.0.1) - actionpack (= 8.0.1) - actionview (= 8.0.1) - activejob (= 8.0.1) - activesupport (= 8.0.1) - mail (>= 2.8.0) - rails-dom-testing (~> 2.2) - actionpack (8.0.1) - actionview (= 8.0.1) - activesupport (= 8.0.1) - nokogiri (>= 1.8.5) - rack (>= 2.2.4) - rack-session (>= 1.0.1) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.2) - rails-html-sanitizer (~> 1.6) - useragent (~> 0.16) - actiontext (8.0.1) - actionpack (= 8.0.1) - activerecord (= 8.0.1) - activestorage (= 8.0.1) - activesupport (= 8.0.1) - globalid (>= 0.6.0) - nokogiri (>= 1.8.5) - actionview (8.0.1) - activesupport (= 8.0.1) - builder (~> 3.1) - erubi (~> 1.11) - rails-dom-testing (~> 2.2) - rails-html-sanitizer (~> 1.6) - activejob (8.0.1) - activesupport (= 8.0.1) - globalid (>= 0.3.6) - activemodel (8.0.1) - activesupport (= 8.0.1) - activerecord (8.0.1) - activemodel (= 8.0.1) - activesupport (= 8.0.1) - timeout (>= 0.4.0) - activestorage (8.0.1) - actionpack (= 8.0.1) - activejob (= 8.0.1) - activerecord (= 8.0.1) - activesupport (= 8.0.1) - marcel (~> 1.0) - activesupport (8.0.1) - base64 - benchmark (>= 0.3) - bigdecimal - concurrent-ruby (~> 1.0, >= 1.3.1) - connection_pool (>= 2.2.5) - drb - i18n (>= 1.6, < 2) - logger (>= 1.4.2) - minitest (>= 5.1) - securerandom (>= 0.3) - tzinfo (~> 2.0, >= 2.0.5) - uri (>= 0.13.1) - addressable (2.8.5) - public_suffix (>= 2.0.2, < 6.0) - ast (2.4.2) - base64 (0.2.0) - bcrypt (3.1.19) - benchmark (0.4.0) - bigdecimal (3.1.9) - bootsnap (1.18.4) - msgpack (~> 1.2) - builder (3.2.4) - concurrent-ruby (1.3.5) - connection_pool (2.5.0) - coveralls (0.7.1) - multi_json (~> 1.3) - rest-client - simplecov (>= 0.7) - term-ansicolor - thor - crass (1.0.6) - database_cleaner-active_record (2.2.0) - activerecord (>= 5.a) - database_cleaner-core (~> 2.0.0) - database_cleaner-core (2.0.1) - date (3.4.1) - debug (1.10.0) - irb (~> 1.10) - reline (>= 0.3.8) - diff-lcs (1.5.0) - docile (1.4.0) - domain_name (0.6.20240107) - drb (2.2.1) - erubi (1.12.0) - factory_bot (6.2.1) - activesupport (>= 5.0.0) - factory_bot_rails (6.2.0) - factory_bot (~> 6.2.0) - railties (>= 5.0.0) - faker (3.2.0) - i18n (>= 1.8.11, < 2) - find_with_order (1.3.1) - activerecord (>= 3) - globalid (1.2.1) - activesupport (>= 6.1) - http-accept (1.7.0) - http-cookie (1.0.8) - domain_name (~> 0.5) - i18n (1.14.1) - concurrent-ruby (~> 1.0) - io-console (0.8.0) - irb (1.15.1) - pp (>= 0.6.0) - rdoc (>= 4.0.0) - reline (>= 0.4.2) - json (2.6.3) - json-schema (3.0.0) - addressable (>= 2.8) - jwt (2.7.1) - language_server-protocol (3.17.0.3) - lingua (0.6.2) - logger (1.6.6) - loofah (2.21.3) - crass (~> 1.0.2) - nokogiri (>= 1.12.0) - mail (2.8.1) - mini_mime (>= 0.1.1) - net-imap - net-pop - net-smtp - marcel (1.0.4) - mime-types (3.6.0) - logger - mime-types-data (~> 3.2015) - mime-types-data (3.2025.0204) - mini_mime (1.1.5) - minitest (5.19.0) - msgpack (1.8.0) - multi_json (1.15.0) - mysql2 (0.5.5) - net-imap (0.5.6) - date - net-protocol - net-pop (0.1.2) - net-protocol - net-protocol (0.2.2) - timeout - net-smtp (0.5.1) - net-protocol - netrc (0.11.0) - nio4r (2.5.9) - nokogiri (1.15.2-aarch64-linux) - racc (~> 1.4) - nokogiri (1.15.2-arm64-darwin) - racc (~> 1.4) - nokogiri (1.15.2-x64-mingw-ucrt) - racc (~> 1.4) - nokogiri (1.15.2-x86_64-linux) - racc (~> 1.4) - parallel (1.23.0) - parser (3.2.2.3) - ast (~> 2.4.1) - racc - pp (0.6.2) - prettyprint - prettyprint (0.2.0) - psych (5.2.3) - date - stringio - public_suffix (5.0.3) - puma (5.6.6) - nio4r (~> 2.0) - racc (1.7.1) - rack (2.2.8) - rack-cors (2.0.1) - rack (>= 2.0.0) - rack-session (1.0.2) - rack (< 3) - rack-test (2.1.0) - rack (>= 1.3) - rackup (1.0.1) - rack (< 3) - webrick - rails (8.0.1) - actioncable (= 8.0.1) - actionmailbox (= 8.0.1) - actionmailer (= 8.0.1) - actionpack (= 8.0.1) - actiontext (= 8.0.1) - actionview (= 8.0.1) - activejob (= 8.0.1) - activemodel (= 8.0.1) - activerecord (= 8.0.1) - activestorage (= 8.0.1) - activesupport (= 8.0.1) - bundler (>= 1.15.0) - railties (= 8.0.1) - rails-dom-testing (2.2.0) - activesupport (>= 5.0.0) - minitest - nokogiri (>= 1.6) - rails-html-sanitizer (1.6.0) - loofah (~> 2.21) - nokogiri (~> 1.14) - railties (8.0.1) - actionpack (= 8.0.1) - activesupport (= 8.0.1) - irb (~> 1.13) - rackup (>= 1.0.0) - rake (>= 12.2) - thor (~> 1.0, >= 1.2.2) - zeitwerk (~> 2.6) - rainbow (3.1.1) - rake (13.0.6) - rdoc (6.12.0) - psych (>= 4.0.0) - regexp_parser (2.8.1) - reline (0.6.0) - io-console (~> 0.5) - rest-client (2.1.0) - http-accept (>= 1.7.0, < 2.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) - rexml (3.2.6) - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-rails (6.0.3) - actionpack (>= 6.1) - activesupport (>= 6.1) - railties (>= 6.1) - rspec-core (~> 3.12) - rspec-expectations (~> 3.12) - rspec-mocks (~> 3.12) - rspec-support (~> 3.12) - rspec-support (3.12.1) - rswag-api (2.16.0) - activesupport (>= 5.2, < 8.1) - railties (>= 5.2, < 8.1) - rswag-specs (2.16.0) - activesupport (>= 5.2, < 8.1) - json-schema (>= 2.2, < 6.0) - railties (>= 5.2, < 8.1) - rspec-core (>= 2.14) - rswag-ui (2.16.0) - actionpack (>= 5.2, < 8.1) - railties (>= 5.2, < 8.1) - rubocop (1.55.1) - json (~> 2.3) - language_server-protocol (>= 3.17.0) - parallel (~> 1.10) - parser (>= 3.2.2.3) - rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) - ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) - parser (>= 3.2.1.0) - ruby-progressbar (1.13.0) - securerandom (0.4.1) - simplecov (0.22.0) - docile (~> 1.1) - simplecov-html (~> 0.11) - simplecov_json_formatter (~> 0.1) - simplecov-html (0.12.3) - simplecov_json_formatter (0.1.4) - spring (4.1.1) - stringio (3.1.5) - sync (0.5.0) - term-ansicolor (1.11.2) - tins (~> 1.0) - thor (1.2.2) - timeout (0.4.3) - tins (1.38.0) - bigdecimal - sync - tzinfo (2.0.6) - concurrent-ruby (~> 1.0) - tzinfo-data (1.2023.3) - tzinfo (>= 1.0.0) - unicode-display_width (2.4.2) - uri (1.0.2) - useragent (0.16.11) - webrick (1.9.1) - websocket-driver (0.7.7) - base64 - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - zeitwerk (2.6.11) - -PLATFORMS - aarch64-linux - arm64-darwin-22 - arm64-darwin-23 - x64-mingw-ucrt - x86_64-linux - -DEPENDENCIES - bcrypt (~> 3.1.7) - bootsnap (>= 1.18.4) - coveralls - database_cleaner-active_record - debug - factory_bot_rails - faker - find_with_order - jwt (~> 2.7, >= 2.7.1) - lingua - mysql2 (~> 0.5.5) - puma (~> 5.0) - rack-cors - rails (~> 8.0, >= 8.0.1) - rspec-rails - rswag-api - rswag-specs - rswag-ui - rubocop - simplecov - simplecov_json_formatter - spring - tzinfo-data - -RUBY VERSION - ruby 3.2.7p253 - -BUNDLED WITH - 2.4.14 diff --git a/config/application.rb b/config/application.rb index 4bd4ca23e..add9503c9 100644 --- a/config/application.rb +++ b/config/application.rb @@ -30,5 +30,7 @@ class Application < Rails::Application # Skip views, helpers and assets when generating a new resource. config.api_only = true config.cache_store = :redis_store, ENV['CACHE_STORE'], { expires_in: 3.days, raise_errors: false } + config.load_defaults 8.0 + config.active_support.to_time_preserves_timezone = :zone end end diff --git a/config/database.yml.example b/config/database.yml.example index b460620e1..1099c2798 100644 --- a/config/database.yml.example +++ b/config/database.yml.example @@ -13,8 +13,8 @@ default: &default adapter: mysql2 encoding: utf8mb4 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - username: dev - password: Root@123 + username: root + password: expertiza development: diff --git a/config/environment.rb b/config/environment.rb index 426333bb4..35c88f632 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -3,3 +3,6 @@ # Initialize the Rails application. Rails.application.initialize! + + + diff --git a/test/models/role_test.rb b/test/models/role_test.rb index 4507a91a8..1bb81021e 100644 --- a/test/models/role_test.rb +++ b/test/models/role_test.rb @@ -85,4 +85,33 @@ class RoleTest < ActiveSupport::TestCase assert_includes other_roles, role3 assert_not_includes other_roles, role1 end + + # Test for invalid role name length + test 'validates name length' do + role = Role.new(name: 'A' * 51) # assuming max length is 50 + assert_not role.valid? + assert_equal ['is too long (maximum is 50 characters)'], role.errors[:name] + + role.name = 'A' * 2 # assuming min length is 3 + assert_not role.valid? + assert_equal ['is too short (minimum is 3 characters)'], role.errors[:name] + end + + # Test for role parent-child relationships + test 'parent-child relationship' do + parent_role = Role.create!(name: 'Parent Role') + child_role = Role.create!(name: 'Child Role', parent: parent_role) + + assert_equal parent_role, child_role.parent + assert_includes parent_role.subordinate_roles, child_role + end + + # Test for role deletion behavior + test 'role deletion cascade' do + parent_role = Role.create!(name: 'Parent Role') + child_role = Role.create!(name: 'Child Role', parent: parent_role) + + parent_role.destroy + assert_raises(ActiveRecord::RecordNotFound) { child_role.reload } + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index d5300f88c..a53747202 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,8 @@ ENV['RAILS_ENV'] ||= 'test' require_relative '../config/environment' require 'rails/test_help' +require 'simplecov' +SimpleCov.start 'rails' class ActiveSupport::TestCase # Run tests in parallel with specified workers From 2a63287b9472fb49283648d9d3ab199a7e017c0a Mon Sep 17 00:00:00 2001 From: sdalal11 Date: Tue, 25 Mar 2025 17:14:03 -0400 Subject: [PATCH 2/3] Update assignment_test.rb --- test/models/assignment_test.rb | 57 ++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/test/models/assignment_test.rb b/test/models/assignment_test.rb index 350ff82ca..64d8a0ff8 100644 --- a/test/models/assignment_test.rb +++ b/test/models/assignment_test.rb @@ -1,7 +1,58 @@ require 'test_helper' class AssignmentTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @assignment = Assignment.new( + name: "Final Project", + description: "Complete the final project for the course.", + due_date: 1.week.from_now + ) + end + + # Test Valid Assignment + test "should be valid" do + assert @assignment.valid? + end + + # Test Name Presence + test "should not save assignment without a name" do + @assignment.name = nil + assert_not @assignment.valid? + end + + # Test Description Presence + test "should not save assignment without a description" do + @assignment.description = nil + assert_not @assignment.valid? + end + + # Test Due Date Presence + test "should not save assignment without a due date" do + @assignment.due_date = nil + assert_not @assignment.valid? + end + + # Test Due Date Validity (Past Dates) + test "should not allow past due dates" do + @assignment.due_date = 1.day.ago + assert_not @assignment.valid? + end + + # Test Associations (Assuming Assignment belongs to a Course) + test "should belong to a course" do + assert_respond_to @assignment, :course + end + + # Test Scope (Assuming a scope `upcoming` exists) + test "should return upcoming assignments" do + @assignment.save + assert_includes Assignment.upcoming, @assignment + end + + # Test Custom Method (If there's a method `overdue?`) + test "should be overdue if due date has passed" do + @assignment.due_date = 1.day.ago + @assignment.save + assert @assignment.overdue? + end end From 0d6955cd88635f757d154dc2030af44e79c8626d Mon Sep 17 00:00:00 2001 From: sdalal11 Date: Tue, 25 Mar 2025 17:14:53 -0400 Subject: [PATCH 3/3] Update user_test.rb --- test/models/user_test.rb | 78 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 82f61e010..0e8094d63 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -1,7 +1,79 @@ require 'test_helper' class UserTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + def setup + @user = User.new( + username: "test_user", + email: "test@example.com", + password: "password123", + password_confirmation: "password123" + ) + end + + # Test valid user + test "should be valid" do + assert @user.valid? + end + + # Test username presence + test "should not save without a username" do + @user.username = nil + assert_not @user.valid? + end + + # Test email presence + test "should not save without an email" do + @user.email = nil + assert_not @user.valid? + end + + # Test password presence + test "should not save without a password" do + @user.password = nil + assert_not @user.valid? + end + + # Test email format + test "should not allow invalid email" do + invalid_emails = ["user@", "user.com", "user@com", "user@example"] + invalid_emails.each do |email| + @user.email = email + assert_not @user.valid?, "#{email.inspect} should be invalid" + end + end + + # Test unique email + test "should not allow duplicate email" do + @user.save + duplicate_user = @user.dup + duplicate_user.email = @user.email.upcase + assert_not duplicate_user.valid? + end + + # Test password length + test "password should be at least 6 characters long" do + @user.password = @user.password_confirmation = "12345" + assert_not @user.valid? + end + + # Test associations (Assuming User has many posts and comments) + test "should have many posts" do + assert_respond_to @user, :posts + end + + test "should have many comments" do + assert_respond_to @user, :comments + end + + # Test authentication (Assuming Devise or has_secure_password is used) + test "should authenticate with valid password" do + @user.save + assert @user.authenticate("password123") + end + + test "should not authenticate with invalid password" do + @user.save + assert_not @user.authenticate("wrongpassword") + end end +